如何找到两个月后的遗骸日期?

时间:2015-02-07 06:39:50

标签: c# sql-server

我有一个数据库Sample with value

Leave    FromDate     ToDate      EmpCode
 6       2015-01-28   2015-02-02    ABC

我想在2015年1月离开= 4,在2015年2月离开计数= 2 有人帮帮我......

eg: You applied 4 days leave 2015-01-30 to 2015-02-02. And the end of the
month your company decide to check your January month leave. They just 
entered month=1 and year=2015. Then how to get count of January month leaves from these data???

If have a date "2015-01-25", then how can I display the remains dates ie, 
2015-01-26,2015-01-27,2015-01-28, 2015-01-29,2015-01-30,2015-01-31 etc.

1 个答案:

答案 0 :(得分:0)

你需要设计一个逻辑。您的方案不仅限于一个月的差距,但也可以扩展几个月。 ex- 2015-01-28至2015-03-01 [可能]

如果您计划在前端实施,请使用DaysInMonth MethodDOC)等方法,并使用相关的propertiesDOC)来提取所需的参数。此外,如果适用,您的逻辑需要注意周末和假日

示例 - 如果您想计算2015-01-28一月假的天数

DateTime dt = DateTime.ParseExact("2015-01-28", "yyyy-MM-dd", CultureInfo.InvariantCulture);
int daysInJan = System.DateTime.DaysInMonth(dt.Year, dt.Month);
Console.WriteLine("Leave for Jan = {0}", (daysInJan - dt.Day)+1); // +1 to include starting date

// Here general holidays are not considered