Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need to compare the date of system by the date of selected date in monthcalender in c#
how can i write the code
if (monthCalendar1.SelectionRange.Start.ToString()= DateTime.Now) ;
what is write code to
Posted
Comments
Sergey Alexandrovich Kryukov 19-Nov-12 15:38pm    
Looks like not a question. Maybe, incomplete question...
--SA

Compare the dates (or, more generally, points of time in the form of System.DateTime using the operators: "==", ">", "<", ">=" and ">=". Also, use "-" (subtraction) to find the time interval, duration.

C#
System.DateTime before = //...
System.DateTime after = //...

//...

if (before == after) { /* same time */ }
if (after >= before) { /* as expected */ }

//...

if (after < before) { /* something's wrong */ }

System.TimeSpan duration = after - before; // as simple as that! now see how much time elapsed


Please see:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^],
http://msdn.microsoft.com/en-us/library/system.timespan.aspx[^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 28-Nov-12 18:15pm    
Nice reply :-D
Sergey Alexandrovich Kryukov 28-Nov-12 19:31pm    
Thank you, Espen.
--SA
Don't do ToString. why on earth would you ? A string comparison will not correctly compare dates. DateTime.Now is NOW. An hour from how is greater, an hour less is less. Remember that. Apart from that, if you remove the ToString, I bet you're getting a DateTime and this would work.
 
Share this answer
 
Comments
meme_307 20-Nov-12 9:55am    
thanks * i made date instead of to string and it works good

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900