This is a discussion on Comparing two Dates within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi, I want to find whether the given date was gone or will come after by checking the current system ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi, I want to find whether the given date was gone or will come after by checking the current system date. I have a labelbox and is entering a date in it. I am comparing it with the system date as follows. DateTime dt = DateTime.Parse(TextBox1.Text); if (DateTime.Compare(dt, DateTime.Now) < 0) Label1.Text = "The date was gone."; else if (DateTime.Compare(dt, DateTime.Now) == 0) Label1.Text = "It is the current date."; else Label1.Text = "The date is yet to come"; The output is only "The date was gone" or "The date is yet to come" and not "It is the current date." Eventhough it is current date the ouput is "The date was gone". So, how can we compare it more effeciently ? I want to know whether the date was gone or is it the current date or it is the future date ? Last edited by Kirubhananth : 03-25-2008 at 12:11 AM. |
| Sponsored Links |
| |||
| Hi Kirubananth, U r using DateTime.Now it will give the Date in the following format like this, 3/25/2008 12:48 PM.U r checking this with the value entered in TextBox 3/25/2008.Both are not equal even if date is same.So it returns "Date has gone".If u entered 3/30/2008.It will return the "Date is yet to come".So Convert the DateFormat using toShortDate and try this... |
| |||
| Thank you madam, I found the error and rectified it as follows DateTime dt = DateTime.Parse(TextBox1.Text); Label2.Text = dt.Day.ToString(); Label3.Text = dt.Month.ToString(); Label4.Text = dt.Year.ToString(); int dat = Convert.ToInt32(Label2.Text); int mon = Convert.ToInt32(Label3.Text); int yr = Convert.ToInt32(Label4.Text); DateTime current = DateTime.Now; int datn = Convert.ToInt32(current.Day.ToString()); int monn = Convert.ToInt32(current.Month.ToString()); int yrn = Convert.ToInt32(current.Year.ToString()); Label sts = new Label(); sts.ID = "statuslbl"; DateTime dt1 = new DateTime(yr, mon, dat); DateTime dt2 = new DateTime(yrn, monn, datn); if (DateTime.Compare(dt1, dt2) < 0) { // The date was gone. } else if (DateTime.Compare(dt1, dt2) == 0) { // Equal } else { // The date is yet to come } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Show all the dates between two dates in YYYY-MM-DD format | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 03-11-2008 09:05 PM |
| Which TSL functions you will use for Comparing the text? | senthilkannan | Testing Tools | 0 | 07-30-2007 03:05 AM |
| Diff. between dates | jegan | PHP Programming | 0 | 07-30-2007 03:02 AM |
| dates | swoosh | VB.NET Programming | 0 | 03-15-2007 07:08 PM |
| Comparing Values | pranky | PHP Programming | 0 | 02-24-2007 01:06 AM |