C# parameters date based on day of week
I want to insert a date in parameters:
If current day is Monday is Friday
If current Tuesday day is Monday
If current day is Wednesday choose Tuesday
If current day is Thursday choose the environment
If current day is Friday to select Thursday
If current Saturday day is selected on Friday
If current Sunday day is Friday
I have a method that selects date according to my condition above
public static DateTime GetDateBackDayStart(DateTime date)
{
int numweek = GetNumWeek(date.DayOfWeek.ToString());
if (numweek == 1)
{
return date.AddDays(-3).Date;
}
if (numweek == 7)
{
return date.AddDays(-2).Date;
}
else
{
return date.AddDays(-1).Date;
}
}
I have a command that returns date in format:
cmd.Parameters.Add("@date1", SqlDbType.DateTime).Value = (DateTime.Today.AddDays(-1).ToString("dd.MM.yyyy"));
cmd.Parameters.Add("@date2", SqlDbType.DateTime).Value = (DateTime.Today.AddDays(-1).ToString("dd.MM.yyyy"));
How to write condition of date substitution in parameters @date1 @date2 in format "dd.MM.yyyy" using the method GetDateBackDayStart?
首先调用GetDateBackDayStart
方法,然后在结果日期中使用ToString
方法:
string dateParam = GetDateBackDayStart(DateTime.Today.AddDays(-1)).ToString("dd.MM.yyyy");
cmd.Parameters.Add("@date1", SqlDbType.DateTime).Value =
cmd.Parameters.Add("@date2", SqlDbType.DateTime).Value = dateParam;
链接地址: http://www.djcxy.com/p/54896.html
上一篇: 反映类型时出现错误
下一篇: C#参数的日期基于星期几