2015-02-07 93 views
-3

我有值的数据库样品如何从两个月的日期找到剩余日期?

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

我想= 4休假数在2015年1月,离开数= 2在2015年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. 
+0

哪个数据库? – 2015-02-07 06:40:38

+1

你应该尝试一下你的逻辑。然后你可以发布你的代码,这会给你任何问题。另外,你的问题是一种悖论,因为你没有提到如何决定哪一个月有多少叶? – 2015-02-07 06:42:20

+0

@MohanLal哪个数据库? 'sqlserver'或'mysql'在后台 – 2015-02-07 06:43:50

回答

0

您需要设计一个逻辑。你的情况不仅限于一个月的差距,但也可以延长几个月。 EX- 2015-01-28至2015年3月1日[可能]

如果您计划在前端,使用方法,如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 
+0

,我的问题可能主要发生在公司。然后他们是如何做到这一点的。如果我添加任何额外的领域,我可以解决它? – 2015-02-07 07:13:12

+0

请参阅代码示例。数据发送到数据库之前,您可以在前端进行此类计算。在这里我没有考虑过公众假期。在真正的行业中,有一些表格可以包含当月的假期,因此可以从计算中扣除它们 – 2015-02-07 07:23:27

相关问题