Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 19-Nov-12 10:12am
Comments
Sergey Alexandrovich Kryukov at 19-Nov-12 15:38pm
   
Looks like not a question. Maybe, incomplete question...
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
 
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

  Permalink  
Comments
Espen Harlinn at 28-Nov-12 18:15pm
   
Nice reply :-D
Sergey Alexandrovich Kryukov at 28-Nov-12 19:31pm
   
Thank you, Espen.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
meme_307 at 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)

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 395
2 Maciej Los 285
3 ProgramFOX 265
4 CHill60 200
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 395
2 Maciej Los 285
3 ProgramFOX 265
4 CHill60 200


Advertise | Privacy | Mobile
Web03 | 2.8.150331.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100