![]() |
Wie viele Tage... Hilfe!
Moin,
aaalso. Ich bräuchte da mal irgendwas Algorithmus-artiges, was am Ende die Anzahl der Tage zwischen zwei Daten ausspuckt, i. e. Geburtsdatum und heute (sprich die beiden sind gegeben, als Tag/Monat/Jahr). Kann mir da mal jemand helfen, weil ich langsam vor lauter Schaltjahr nicht mehr richtig durchblicke... :rolleyes: TIA, Etienne PS. Ooops, also ich spreche von C/C++. |
Du brauchst ja nur die Anzahl der Tage pro Jahr vom Jahr 0 weg aufsummieren bis zum vorletzten Jahr des gegebenen Datums und dann die Tage des aktuellen Jahres hinzuzählen.
Dieses für das Startdatum und das Enddatum gemacht und die Differenz gebildet gibt die Anzahl an Tagen zwischen Datum A und Datum B. Die Formel bezüglich 365 oder 366 Tage im Jahr lautet auf: tage=365; if( (jahr % 4) == 0 ) if( (jahr % 100) != 0 ) tage=366; else if( (jahr % 400) == 0) tage=366; |
Ein ähnliches Programm (wenn du die Library verwenden willst):
/* The example takes a number of days * as input and returns the time, the current * date, and the specified number of days. */ #include <time.h> #include <stdio.h> void main( void ) { struct tm when; __time64_t now, result; int days; _time64( &now ); when = *_localtime64( &now ); printf( "Current time is %s\n", asctime( &when ) ); printf( "How many days to look ahead: " ); scanf( "%d", &days ); when.tm_mday = when.tm_mday + days; if( (result = _mktime64( &when )) != (time_t)-1 ) printf( "In %d days the time will be %s\n", days, asctime( &when ) ); else perror( "_mktime64 failed" ); } |
Re: Wie viele Tage... Hilfe!
gelöscht
|
Re: Wie viele Tage... Hilfe!
Zitat:
[IMG]Siehe Bild im Anhang[/IMG] |
Jup jup... Hab's hinbekommen, danke. :)
BTW, @ Flink: Schickes Programm da... hehehe ;) |
gelöscht
|
| Alle Zeitangaben in WEZ +2. Es ist jetzt 02:24 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag