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

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

inline unsigned __int64 to_integral( const SYSTEMTIME& st )
{
   FILETIME ft ;
   SystemTimeToFileTime( &st, &ft ) ;
   ULARGE_INTEGER integer ;
   integer.LowPart = ft.dwLowDateTime ;
   integer.HighPart = ft.dwHighDateTime ;
   return integer.QuadPart ;
}

inline bool operator== ( const SYSTEMTIME& a, const SYSTEMTIME& b )
{ return to_integral(a) == to_integral(b) ; }
inline bool operator< ( const SYSTEMTIME& a, const SYSTEMTIME& b )
{ return to_integral(a) < to_integral(b) ; }
inline bool operator<= ( const SYSTEMTIME& a, const SYSTEMTIME& b )
{ return to_integral(a) <= to_integral(b) ; }
inline bool operator!= ( const SYSTEMTIME& a, const SYSTEMTIME& b ) 
{ return !( a==b ) ; }
inline bool operator> ( const SYSTEMTIME& a, const SYSTEMTIME& b ) 
{ return !( a<=b ) ; }
inline bool operator>= ( const SYSTEMTIME& a, const SYSTEMTIME& b ) 
{ return !( a<b ) ; }

it will compare even the time. but i only want to compare is the date disregard the time..

anyway thanks for the help.

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

This article has been dead for over six months. Start a new discussion instead.