如何在 SSIS 脚本任务中获取月初的日期?
How to get the date of the beginning of the month in SSIS Script Task?
我正在使用 SSIS,并且我有一个脚本任务,如果今天的日期是月初,我想更改变量的值。
所以我想将布尔变量 startDate
的值更改为 TRUE,如果它是任务运行的月初,否则为 FALSE。
基本上我缺少此 SQL 语句的 SSIS 脚本版本:
SELECT DATEADD(month, DATEDIFF(month, 0, @mydate), 0) AS StartOfMonth
到目前为止,这是我的脚本:
public void Main()
{
if (DateTime.Today = ? )
{
Dts.Variables["User::startDate"].Value = True;
}
Dts.Variables["User::startDate"].Value = False;
Dts.TaskResult = (int)ScriptResults.Success;
}
}
答案:
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;
}
}
只需使用:
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;
}
}
我正在使用 SSIS,并且我有一个脚本任务,如果今天的日期是月初,我想更改变量的值。
所以我想将布尔变量 startDate
的值更改为 TRUE,如果它是任务运行的月初,否则为 FALSE。
基本上我缺少此 SQL 语句的 SSIS 脚本版本:
SELECT DATEADD(month, DATEDIFF(month, 0, @mydate), 0) AS StartOfMonth
到目前为止,这是我的脚本:
public void Main()
{
if (DateTime.Today = ? )
{
Dts.Variables["User::startDate"].Value = True;
}
Dts.Variables["User::startDate"].Value = False;
Dts.TaskResult = (int)ScriptResults.Success;
}
}
答案:
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;
}
}
只需使用:
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;
}
}