Re: Anzahl das im Monat
warum kann man nicht das mit dem schaltjahr so leicht herausfinden??
|
Re: Anzahl das im Monat
Zitat:
@Susanne: Gibt es vielleicht eine gleichnamige Funktion aus einer anderen Unit als DateUtils, welche vorher eingebunden wird? |
Re: Anzahl das im Monat
Keine Ahnung, was du falsch machst, aber bei mir funktioniert das:
Delphi-Quellcode:
uses
DateUtils; procedure TForm1.Button1Click(Sender: TObject); var days: Cardinal; begin days := DaysInMonth(now); ShowMessage(IntToStr(days)); end; |
Re: Anzahl Tage im Monat
ok, man sollte den Wert vielleicht auch aus der Funktion wieder zurückgeben, sobald ich dies an result übergebe funktioniert es auch.
Trotzdem vielen Dank für eure Hilfe. Ich hab vermutet, es musste irgendeine "Kleinigkeit" sein. |
Re: Anzahl Tage im Monat
sonst dieses script hätte auch funkitioniert
Delphi-Quellcode:
function TForm1.getdaysinmonth(date: TDATETIME): integer;
const monthday: array[1..12] of integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); begin if strtoint(formatdatetime('m', date)) <> 2 then begin result := monthday[strtoint(formatdatetime('m', date))]; end else begin if round(strtoint(formatdatetime('yyyy', date)) / 4) = strtoint(formatdatetime('yyyy', date)) / 4 then result := 29 else result := 28; end; end; |
Re: Anzahl Tage im Monat
Zitat:
|
Re: Anzahl Tage im Monat
seit wann denn das
|
Re: Anzahl Tage im Monat
Noch mal, es reicht nicht zu überprüfen ob ein Jahr durch vier Teilbar ist, um herauszufiden, ob es sich ume ine Schaltjahr handelt:
Zitat:
Zitat:
|
Re: Anzahl Tage im Monat
dann fügt man das einfach mit hinzu
Delphi-Quellcode:
wo ist das problem??
function TForm1.getdaysinmonth(date: TDATETIME): integer;
const monthday: array[1..12] of integer = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); begin if strtoint(formatdatetime('m', date)) <> 2 then begin result := monthday[strtoint(formatdatetime('m', date))]; end else begin if (round(strtoint(formatdatetime('yyyy', date)) / 4) = strtoint(formatdatetime('yyyy', date)) / 4) and not(round(strtoint(formatdatetime('yyyy', date)) / 400) = strtoint(formatdatetime('yyyy', date)) / 400) then result := 29 else result := 28; end; end; |
Re: Anzahl Tage im Monat
@IIIMADDINIII:Dein Code hat mehrere Probleme:
1. Parametername Date: Ist auche ien Funktion. Es ist nicht sichergestellt, das der richtige Wert verwendet wird. 2. Ablage der Werte in einem array ist überflüssig. 3. Wandlung DateTime->String->Integer ist aufwendig besser gleich in einen Integer wandeln (DecodeDate()) 4. Der Algorithmus ist komplexer: Wenn durch 4 teilbar aber nicht durch 100 (nur wenn durch 400 teilbar sind) 1900 war kein Schaltjahr aber 2000. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:23 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz