根据文本框中的日期选择计算天数 [英] Calculate no of days on basis of date selection in textbox

查看:95
本文介绍了根据文本框中的日期选择计算天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在两个文本框上有两个ajax日历控件,作为开始日期和结束日期,并且有一个Label.Now,这是因为用户输入在endate文本框上选择日期时的开始日期和结束日期应该很快就会在Label.I中使用onblur结束日期事件,但它在选择完成日期之前触发,并且错误以无效形式生成日期。



如果你有人提供其他解决方案,请告诉我。



感谢你

mohammad Wasif

Hi All,

I have two ajax calender control on two textboxes as start date and end date and having a Label.Now the thing is this as user enter start date and end date on selection of date on endate textbox no of days should be soon in Label.I used onblur event of end date but it's firing before selection complete date and the error is generating as date in invalid form.

Please let me know if u people have another solution.

thanking you
mohammad Wasif

推荐答案

试试这个





在结束日期_文本更改于编码方



DateTime sDateTime = Convert.ToDateTime(startdate.Text);

DateTime eDateTime = Convert.ToDateTime(enddate.Text);

System.TimeSpan span = eDateTime - sDateTime;

int ddays =(int)span.TotalDays;

label.Text = ddays.ToString ( );
try this one


at end date_Text Changed at coding side

DateTime sDateTime = Convert.ToDateTime(startdate.Text);
DateTime eDateTime = Convert.ToDateTime(enddate.Text);
System.TimeSpan span = eDateTime - sDateTime;
int ddays = (int)span.TotalDays;
label.Text=ddays.ToString();


为什么不使用Calendar控件?这样你总是有一个合理的约会,并且用户不会犯错并以错误的格式输入...

MSDN [ ^ ]
Why not use a Calendar control instead? That way you always have a sensible date, and the user can't make a mistake and enter it in the wrong format...
MSDN[^]


这篇关于根据文本框中的日期选择计算天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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