如何检查结束日期小于开始日期? [英] How can i check End date is less than Start Date?

查看:77
本文介绍了如何检查结束日期小于开始日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想输入员工的薪水,我想通过文本框输入开始日期和结束日期,如何检查用户输入的结束日期不能小于或等于开始日期.
请告诉我.....

i want to enter the salary of an Employee and i Want to enter the Start Date and End Date through Text Boxes and how can i check that user can''t enter the End date not less than or equal to Start Date.
please tell me.....

推荐答案

首先,不要使用文本框-改用DateTimePicker.这样可以确保日期始终有效,这样就无需检查2月31日,依此类推.
那么实际的检查是
Firstly, don''t use text boxes - use a DateTimePicker instead. This ensures that the dates are always valid which removes the need for you to check for 31st February, and so forth.
The actual check is then
if (startDateTimePicker.Value < endDateTimePicker.Value)
   {
   // All ok
   }


您可以在哪里进行此测试-但是我会在接受提交"按钮之前将其作为最终检查.大多数用户会在遇到问题时收到警报,这很烦人,特别是如果您使用MessageBox或类似工具来完成通知他们的工作.


Where you do this test is up to you - but I would do it as a final check just before accepting the submit button. Most users find it annoying to be alerted to a problem as they go along, particularly if you use a MessageBox or similar to do the job of informing them.


下面的链接向您提供了一个想法将字符串或textbox.text转换为日期时间.
将u转换为日期时间后,逻辑很简单.

http://msdn.microsoft.com/en-us/library/1k1skd40.aspx [ ^ ]
Following link gives you the idea how to convert string or your textbox.text to datetime.
Once u convert to datetime the logic is simple.

http://msdn.microsoft.com/en-us/library/1k1skd40.aspx[^]


Manjit,

Manjit,

DateTime startdate = DateTime.Now;
            DateTime enddate = DateTime.Now.AddDays(10);
            //DateTime enddate = DateTime.Now.AddDays(-10);

            if(startdate > enddate)
            {
                Console.WriteLine("Start date is greater than end date");
                //do somthing 
            }else
            {
                Console.WriteLine("End date is greater than start date");
                //do something
            }
            Console.Read();


这篇关于如何检查结束日期小于开始日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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