Autor Beitrag
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Do 26.02.09 17:19 
Morgen,

ich möchte über folgendes einfach den Wochentag des eingegebenen Datums herausfinden..

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
var
  Form1: TForm1;
  Geburtstag,Datum1,Datum2 : TDateTime;
  myDate : TDateTime;
  myYear, myMonth, myDay : Word;
  myHour, myMin, mySec, myMilli : Word;
  day:array[1..7of string;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Datum1:=Now;
  Datum2:=StrToDate(MaskEdit1.Text);
  Label5.Caption:=IntToStr(YearsBetween(Datum1,Datum2));
  Label6.Caption:=IntToStr(MonthsBetween(Datum1,Datum2));
  Label7.Caption:=IntToStr(DaysBetween(Datum1,Datum2));
  Label8.Caption:=IntToStr(HoursBetween(Datum1,Datum2));
  Label10.Caption:=IntToStr(MinutesBetween(Datum1,Datum2));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  DecodeDateTime(Datum2,myYear, myMonth, myDay,
                 myHour, myMin, mySec, myMilli);

  day[1] := 'Montag';
  day[2] := 'Dienstag';
  day[3] := 'Mittwoch';
  day[4] := 'Donnerstag';
  day[5] := 'Freitag';
  day[6] := 'Samstag';
  day[7] := 'Sonntag';

  ShowMessage('Dein Geburtstag war an einem '+day[DayOfTheWeek(myday)]);
end;

end.


Nur immer wenn ich ein Datum eingeben zum Beispiel mein Geburtsdatum was der 02.12.1990 ist, und ich somit an einem Sonntag geboren wurde gibt er mir z.B einen Montag aus..

Wo liegt hier der Fehler ?

LG

GericasS

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Do 26.02.09 17:21 
Beginnt die Woche nicht immer mit Sonntag? Zumindest in Delphi?

Da habe ich das Wörtchen "The" übersehen.
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Do 26.02.09 17:24 
user profile iconRegan hat folgendes geschrieben Zum zitierten Posting springen:
Beginnt die Woche nicht immer mit Sonntag? Zumindest in Delphi?

Da habe ich das Wörtchen "The" übersehen.


Hey Regan,

ich glaube ich meinen Fehler gefunden :

ShowMessage('Dein Geburtstag war an einem '+day[DayOfTheWeek(myday)]);

ShowMessage('Dein Geburtstag war an einem '+day[DayOfTheWeek(Datum2)]);

trotzdem danke für die Hilfe

LG

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
Stundenplan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128
Erhaltene Danke: 32

Win 7
Delphi 7 Pers., C# (VS 2010 Express)
BeitragVerfasst: Do 05.03.09 21:05 
Übrigens: Es gibt schon so eine Funktion in Delphi: dayOfWeek(DateTime): integer;
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var d: integer;
str: String;
begin
d := dayOfWeek(StrToDateTime(Edit1.Text));
case d of
0: str := 'Samstag';
1: str := 'Sonntag';
2: str := 'Montag';
3: str := 'Dienstag';
4: str := 'Mittwoch';
5: str := 'Donnerstag';
6: str := 'Freitag';
end;
ShowMessage('Du wurdest an einem '+str+' geboren!');
end;

(Nicht komplett getestet!)
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Do 05.03.09 21:16 
user profile iconStundenplan hat folgendes geschrieben Zum zitierten Posting springen:
Übrigens: Es gibt schon so eine Funktion in Delphi: dayOfWeek(DateTime): integer;
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var d: integer;
str: String;
begin
d := dayOfWeek(StrToDateTime(Edit1.Text));
case d of
7: str := 'Samstag';
1: str := 'Sonntag';
2: str := 'Montag';
3: str := 'Dienstag';
4: str := 'Mittwoch';
5: str := 'Donnerstag';
6: str := 'Freitag';
end;
ShowMessage('Du wurdest an einem '+str+' geboren!');
end;

(Nicht komplett getestet!)

Ist komplett falsch. Die Funktion sieht wie hier aus. Außerdem wurde hier nach "of the week" gefragt. Bei deiner Variante wird der Sonntag als erster Tag genannt, bei der Variante mit the ist der Montag der erste Tag.