SYSTEMTIME - prüfen, ob Datum größer als das andere?



  • Hi ich habe mal wieder ein Problem und wollte es Euch nicht vorenthalten! 🙂
    Also ich habe zwei mal an Datum gespeichert. SYSTEMTIME st1, st2;
    In beiden steht also ein bestimmtes Datum. Habt Ihr eine Ahnung, wie ich jetzt prüfen kann, ob st1 größer ist als st2? Weil ich schreibe ein Datereminder, und der muss es mir melden sobald st1 größer ist als st2 (Termin ist fällig)... Wisst Ihr Rat?



  • Mit SystemTimeToFileTime und dann CompareFileTime sollte das möglich sein!



  • Wahnsinn, habe die Funktionen nie entdeckt!!! Thx 1000 mal!



  • flenders schrieb:

    Mit SystemTimeToFileTime und dann CompareFileTime sollte das möglich sein!

    Ich weiß, der Thread ist schon alt. Aber ich hatte gerade das gleice Problem ;).

    Warum macht es die WinAPI hier so umständlich zwei SYSTEMTIME miteinander zu vergleichen?

    Edit: Mir ist schon klar, dass diese auf C basierende API keinen Operator überladen kann - aber eine Funktion dafür wird ja sicherlich oft benötigt!

    MfG SideWinder



  • Kannst es ja so für alle benötigten Strukturen machen und dann freigeben:

    bool operator >(const SYSTEMTIME& st1,const SYSTEMTIME& st2)
    {
    	FILETIME ft[2];
    	SystemTimeToFileTime(&st1,&ft[0]);
    	SystemTimeToFileTime(&st2,&ft[1]);
    	return CompareFileTime(&ft[0],&ft[1]) > 0;
    }
    
    bool operator <(const SYSTEMTIME& st1,const SYSTEMTIME& st2)
    {
    	FILETIME ft[2];
    	SystemTimeToFileTime(&st1,&ft[0]);
    	SystemTimeToFileTime(&st2,&ft[1]);
    	return CompareFileTime(&ft[0],&ft[1]) < 0;
    }
    
    bool operator ==(const SYSTEMTIME& st1,const SYSTEMTIME& st2)
    {
    	return memcmp(&st1,&st2,sizeof st1) == 0;
    }
    
    // usw.
    


  • Nemesyzz schrieb:

    Kannst es ja so für alle benötigten Strukturen machen und dann freigeben:

    bool operator >(const SYSTEMTIME& st1,const SYSTEMTIME& st2)
    {
    	FILETIME ft[2];
    	SystemTimeToFileTime(&st1,&ft[0]);
    	SystemTimeToFileTime(&st2,&ft[1]);
    	return CompareFileTime(&ft[0],&ft[1]) > 0;
    }
    
    bool operator <(const SYSTEMTIME& st1,const SYSTEMTIME& st2)
    {
    	FILETIME ft[2];
    	SystemTimeToFileTime(&st1,&ft[0]);
    	SystemTimeToFileTime(&st2,&ft[1]);
    	return CompareFileTime(&ft[0],&ft[1]) < 0;
    }
    
    bool operator ==(const SYSTEMTIME& st1,const SYSTEMTIME& st2)
    {
    	return memcmp(&st1,&st2,sizeof st1) == 0;
    }
    
    // usw.
    

    Mir reicht der <-Operator :).

    MfG SideWinder


Anmelden zum Antworten