Jonathan Porter Jonathan Porter - 1 month ago 7
SQL Question

How to get the date of the beginning of the month in SSIS Script Task?

I'm using SSIS and I have a script task that I want to change the value of a variable if today's date is the beginning of the month.

So I would like to change the value of the boolean variable

startDate
to TRUE if it's the beginning of the month when the task runs and FALSE otherwise.

Essentially I'm missing the SSIS Script version of this SQL statement:

SELECT DATEADD(month, DATEDIFF(month, 0, @mydate), 0) AS StartOfMonth


Here is my script so far:

public void Main()
{
if (DateTime.Today = ? )
{
Dts.Variables["User::startDate"].Value = True;
}
Dts.Variables["User::startDate"].Value = False;

Dts.TaskResult = (int)ScriptResults.Success;
}
}

Answer

Just use :

public void Main()
{

  DateTime value = new DateTime(DateTime.Today.Year,DateTime.Today.Month,1);

    if (DateTime.Today == value )
    {
        Dts.Variables["User::startDate"].Value = bool.Parse("True");
    }
        Dts.Variables["User::startDate"].Value = bool.Parse("False");

    Dts.TaskResult = (int)ScriptResults.Success;
}
}
Comments