User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,428 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,614 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1386 | Replies: 4
Reply
Join Date: Aug 2007
Posts: 2
Reputation: Allan03 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Allan03 Allan03 is offline Offline
Newbie Poster

How to Compare two SYSTEMDATE?

  #1  
Aug 3rd, 2007
I can't find way to compare two dates (SYSTEMTIME). I need to know if the date1 is greater than or equal to date2.

Thnx in advanced...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 972
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: How to Compare two SYSTEMDATE?

  #2  
Aug 3rd, 2007
convert them to doubles using SystemTimeToVariantTime() then its trivel to compare them.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Dec 2006
Location: india
Posts: 1,085
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Rep Power: 9
Solved Threads: 163
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: How to Compare two SYSTEMDATE?

  #3  
Aug 3rd, 2007
Dragon's suggestion of SystemTimeToVariantTime is the easiest way, but might give you inaccurate resuts if you need sub-second resolution for time. see: http://support.microsoft.com/kb/297463
if you need millisecond resolution, more work is required
  1. inline unsigned __int64 to_integral( const SYSTEMTIME& st )
  2. {
  3. FILETIME ft ;
  4. SystemTimeToFileTime( &st, &ft ) ;
  5. ULARGE_INTEGER integer ;
  6. integer.LowPart = ft.dwLowDateTime ;
  7. integer.HighPart = ft.dwHighDateTime ;
  8. return integer.QuadPart ;
  9. }
  10.  
  11. inline bool operator== ( const SYSTEMTIME& a, const SYSTEMTIME& b )
  12. { return to_integral(a) == to_integral(b) ; }
  13. inline bool operator< ( const SYSTEMTIME& a, const SYSTEMTIME& b )
  14. { return to_integral(a) < to_integral(b) ; }
  15. inline bool operator<= ( const SYSTEMTIME& a, const SYSTEMTIME& b )
  16. { return to_integral(a) <= to_integral(b) ; }
  17. inline bool operator!= ( const SYSTEMTIME& a, const SYSTEMTIME& b )
  18. { return !( a==b ) ; }
  19. inline bool operator> ( const SYSTEMTIME& a, const SYSTEMTIME& b )
  20. { return !( a<=b ) ; }
  21. inline bool operator>= ( const SYSTEMTIME& a, const SYSTEMTIME& b )
  22. { return !( a<b ) ; }
Reply With Quote  
Join Date: Aug 2007
Posts: 2
Reputation: Allan03 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Allan03 Allan03 is offline Offline
Newbie Poster

Re: How to Compare two SYSTEMDATE?

  #4  
Aug 3rd, 2007
it will compare even the time. but i only want to compare is the date disregard the time..

anyway thanks for the help.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 972
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: How to Compare two SYSTEMDATE?

  #5  
Aug 3rd, 2007
set all the time fields in the structure to 0 then convert. Or, alternatively, you could call modf() to split the double into integer and fractional parts, then compare only the integer parts (the fractional part contains the time and integer part is the date).
Last edited by Ancient Dragon : Aug 3rd, 2007 at 7:26 am.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 1:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC