Date
-
I want to compare between two dates. One date is System Date mm/dd/yyyy format Other one is User i/p Date in SAME FORMAT. I want to check whether the User I/P date is greater/less/euqal than the system date. How can I compare between them
-
I don't know what you mean by:
simworld wrote:
Other one is User i/p Date
Anyway, you can compare dates as following
myDate1 > myDate2 or myDate1 <= myDate2, etc
I want to say.. I have a table that contains columns with date value(System date). In a form a Text box (User i/p)that takes only date in a mm/dd/yyyy format if user date will be greater/less/equal than the system date,then certain event will occur. I want the C# code syntax that will compare those date. i think this give u clear view what my question is??
-
I want to say.. I have a table that contains columns with date value(System date). In a form a Text box (User i/p)that takes only date in a mm/dd/yyyy format if user date will be greater/less/equal than the system date,then certain event will occur. I want the C# code syntax that will compare those date. i think this give u clear view what my question is??
The date comparison examples I gave before would be how you compare dates. I'm guessing what you mean is that you want to make sure that the user enters a valid date and compare that to another date. To do this you can implement code similar to this:
DateTime systemDate = DateTime.Today; DateTime userInputDate; // Try to determine if the user entered a valid date. // If it is, userInputDate will have the date value bool bValidDate = DateTime.TryParse(textBox.Text, out userInputDate); if (!bValidDate) { // Invalid date entered, alert user MessageBox.Show(textBox.Text + " is not a valid date!"); } else { //Perform date comparison if (systemDate < userInputDate) { } }
-
I want to compare between two dates. One date is System Date mm/dd/yyyy format Other one is User i/p Date in SAME FORMAT. I want to check whether the User I/P date is greater/less/euqal than the system date. How can I compare between them
-
I want to compare between two dates. One date is System Date mm/dd/yyyy format Other one is User i/p Date in SAME FORMAT. I want to check whether the User I/P date is greater/less/euqal than the system date. How can I compare between them
The best way I have found is to subtract one DateTime from another, creating a TimeSpan object. Then use the result of the TimeSpan object to do your testing. Hope this helps! DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Now.AddDays(1); //Compare TimeSpan ts = dt1 - dt2; if (ts.TotalMinutes < 50) { //do good stuff here } Hogan
-
I want to say.. I have a table that contains columns with date value(System date). In a form a Text box (User i/p)that takes only date in a mm/dd/yyyy format if user date will be greater/less/equal than the system date,then certain event will occur. I want the C# code syntax that will compare those date. i think this give u clear view what my question is??
Use a DateTimePicker, not a TextBox.
-
I want to compare between two dates. One date is System Date mm/dd/yyyy format Other one is User i/p Date in SAME FORMAT. I want to check whether the User I/P date is greater/less/euqal than the system date. How can I compare between them