Please help to get the SSIS expression of First Day and Last Day of Previous month

Subhomoy Chakraborty 106 Reputation points
2022-10-06T20:18:25.4+00:00

Can anybody please help me to get the SSIS expression of First Day and Last Day of Previous month in the below format.

yyyy-mm-dd.

Currently I am hardcoding it as 2022-09-01 and 2022-09-30 respectively.

Any suggestion will be helpful.

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,704 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yitzhak Khabinsky 26,586 Reputation points
    2022-10-07T00:45:09.777+00:00
    0 comments No comments

  2. ZoeHui-MSFT 41,496 Reputation points
    2022-10-07T01:57:34.813+00:00

    Hi @Subhomoy Chakraborty ,

    First Day:

    (DT_WSTR, 4)YEAR(DATEADD("mm", -1, GETDATE())) +"-"+ RIGHT("0" + (DT_WSTR,2)MONTH(DATEADD("mm", -1, GETDATE())),2)+"-"+"01"  
    

    Last Day:

    (DT_WSTR,4) YEAR(DATEADD( "day", -DAY( GETDATE() ) ,GETDATE())) + "-"  
    +RIGHT("0"+(DT_WSTR,2) MONTH(DATEADD( "day",  -DAY( GETDATE()),GETDATE()) ), 2) +"-"+RIGHT("0"+(DT_WSTR,2) DAY(DATEADD( "day",  -DAY( GETDATE()) ,GETDATE()) ),2)  
    

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.