怀疑是否要计算两个日期之间的天数并将其存储在数据库中. [英] doubt on calculate the no.of days between 2 dates and store it in database.

查看:68
本文介绍了怀疑是否要计算两个日期之间的天数并将其存储在数据库中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个文本框,即
1.)开始日期
2.)结束日期
3.)没有叶子
当我选择开始日期和结束日期时,它应该自动计算天数并将其显示在叶数"文本框中并存储在数据库中.
叶子数文本框的编号应为只读.
所以,请帮我.

I have 3 textboxes namely
1.)Start Date
2.)End Date
3.)No of Leaves
when i select the start date and end date it should automatically calculate the no of days and display it in the no.of leaves textbox and to be stored in the database.
the no of leaves textbox should be readonly.
so,plz help me out .

推荐答案


代替文本框,最好使用DateTimePicker控件.因此,计算将更加容易.

您可以使用以下代码查找日期差异.

Hi
Instead of text boxes, it is better to use DateTimePicker control. So the calculations will be easier.

You can use the below code find the difference in dates .

TimeSpan dtDiff =   dtEnd.Value.Subtract(dtStart.Value);
         int iDiffValue  = dtDiff.Days;




问候
Dominic




Regards
Dominic


可以使用DateTime.Compare方法,如下所示

You can use DateTime.Compare method as shown below

NumLeaves.Text = DateTime.Compare(date1, date2).ToString();


NumLeaves是您的文本框,其中显示了叶数

希望能有所帮助.如果是这样,请将其标记为答案/赞.

Milind


Here NumLeaves is your textbox showing number of leaves

Hope that helps. If it does, mark it as answer/upvote.

Milind


您是否在计算员工休假的数量?如果是这样,您可能应该只计算工作日.看看此StackOverflow答案 [
Are you calculating the amount of leave an employee is taking? If so, you should probably only count the business days. Have a look at this StackOverflow answer[^]


这篇关于怀疑是否要计算两个日期之间的天数并将其存储在数据库中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆