Autor Beitrag
ibh_compucat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win 2000, Win 8.1
D6, Ent. XE5 Ent.
BeitragVerfasst: Fr 16.09.05 13:30 
Hallo,

es gibt Monate mit 28, 29, 30 oder 31 Tagen. Wie kann ich abfragen, wieviel Tage ein zufällig ausgewählter Monat hat?

Gruß ibh_compucat

_________________
Was du nicht begreifst, kannst du nicht verlernen!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 16.09.05 13:33 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
case monat of
  1,3,5,7,8,10,12 : Tage := 31;
  2 : begin
    if isleapyear(Date) then Tage = 29 else Tage = 28;
  end;
  else Tage := 30;
end;

oder so ähnlich.
SpaghettiCodix
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52
Erhaltene Danke: 1

WIN XP
Delphi 2 Standart und Delphi 2005 Pers.
BeitragVerfasst: Fr 16.09.05 13:34 
Titel: Re: Zeitberechnung: der wievielte ist der letzte Tag im Mona
user profile iconibh_compucat hat folgendes geschrieben:
Hallo,

es gibt Monate mit 28, 29, 30 oder 31 Tagen. Wie kann ich abfragen, wieviel Tage ein zufällig ausgewählter Monat hat?

Gruß ibh_compucat


Ist aber nicht von mir:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
function LastDayOfCurrentMonth: TDateTime;
var
  y, m, d: Word;
begin
  DecodeDate(now, y, m, d);
  m := m + 1;
  if m  = 12 then
  begin
    y := y + 1;
    m := 1;
  end;
  Result := EncodeDate(y, m, 1) - 1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(DateToStr(LastDayOfCurrentMonth));
end;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 16.09.05 13:44 
Kannst aber auch einfach so machen:
ausblenden Delphi-Quelltext
1:
Tag = DaysInAMonth(2005, 5);					

Ist vielleicht etwas kürzer als die anderen Methoden.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
ibh_compucat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win 2000, Win 8.1
D6, Ent. XE5 Ent.
BeitragVerfasst: Fr 16.09.05 13:48 
Danke an euch Beide, damit kann ich was anfangen.

Gruß
ibh_compucat

_________________
Was du nicht begreifst, kannst du nicht verlernen!
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 16.09.05 13:51 
Mh... Ich seh zwar 3 Posts, aber wenn du mit beide alle 3 meinst... OK :wink:

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
ibh_compucat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win 2000, Win 8.1
D6, Ent. XE5 Ent.
BeitragVerfasst: Fr 16.09.05 13:59 
Hallo GTA Place,

nein, das Problem war daß Deine Antwort zwischenzeitlich noch kam, entschuldige bitte.
Aber ich habe noch eine Frage zu Deiner Lösung: mein Delphi6 kennt die Funktion offensichtlich nicht oder muß man da eine spezielle UNIT noch einbinden?

Gruß ibh_compucat

_________________
Was du nicht begreifst, kannst du nicht verlernen!
ibh_compucat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win 2000, Win 8.1
D6, Ent. XE5 Ent.
BeitragVerfasst: Fr 16.09.05 14:04 
Hallo,

habs gefunden, ist die UNIT DateUtils!

Nochmals Danke an alle!

Gruß ibh_compucat

_________________
Was du nicht begreifst, kannst du nicht verlernen!
Alpha_Wolf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 297

Ubuntu, Win XP, Win Vista
C#, Delphi 6 Prof, Delphi 2007 Prof, Java
BeitragVerfasst: Fr 16.09.05 14:06 
user profile iconibh_compucat hat folgendes geschrieben:

Aber ich habe noch eine Frage zu Deiner Lösung: mein Delphi6 kennt die Funktion offensichtlich nicht oder muß man da eine spezielle UNIT noch einbinden?


Die Unit "DateUtils" einbinden, das hilft.

function DaysInAMonth(const AYear, AMonth: Word): Word;

Ist wohl die beste Lösung so wie GTA-Place meinte.

Edit.. sorry.. war wohl zu langsam :oops: