I can't find way to compare two dates (SYSTEMTIME). I need to know if the date1 is greater than or equal to date2.

## All 4 Replies

convert them to doubles using SystemTimeToVariantTime() then its trivel to compare them.

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 ;
}

inline bool operator== ( const SYSTEMTIME& a, const SYSTEMTIME& b )
inline bool operator< ( const SYSTEMTIME& a, const SYSTEMTIME& b )
inline bool operator<= ( const SYSTEMTIME& a, const SYSTEMTIME& 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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.