Autor Beitrag
The_Tremendous
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47

Win XP SP2
Borland Delphi 6
BeitragVerfasst: So 19.06.05 13:49 
Ich hoffe mal, dass ich das in diesem Forum fragen darf, da es sich hier um ein Pascal Programm hadelt.

Also ich lese zwei daten ein, date1, und date 2.

readln(date1);
readln(date2);

Die eingelesenen daten sind sringwerte.

Ich muss jetzt eine Funktion schreiben, die die Anzahl der Tage zwischen den beiden DAten berechnet.

Könnt ihr mir da helfen?? Leider gibt es keinen Datumstypen unter pascal.


Ich muss das Programm mit Dev-Pascal schreiben.


The-Tremendous
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 19.06.05 13:57 
Welche Typen haben bei dir date1 und date2?

AXMD
The_Tremendous Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47

Win XP SP2
Borland Delphi 6
BeitragVerfasst: So 19.06.05 14:04 
Die Variablen date1 und date2 sind beide Strings
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 19.06.05 14:05 
Da hilft nur eins: die Strings zerlegen in Tag, Monat und Jahr und dann jeweils separat die Unterschiede herausrechnen

AXMD
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 19.06.05 14:06 
user profile iconAXMD hat folgendes geschrieben:
Welche Typen haben bei dir date1 und date2?

user profile iconThe_Tremendous hat folgendes geschrieben:
Die eingelesenen daten sind sringwerte.


UI ^^ Mod, der nicht lesen kann ^^

Aber nun zum Thema: Beide Werte mit StrToDateTime in TDateTime-Werte umwandeln und dann DateDiff := Date2-Date1; rechnen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 19.06.05 14:17 
Ui, ein BenBE, der auch nicht lesen kann :mrgreen:

user profile iconThe_Tremendous hat folgendes geschrieben:
da es sich hier um ein Pascal Programm hadelt. [..] Leider gibt es keinen Datumstypen unter pascal.


AXMD
The_Tremendous Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47

Win XP SP2
Borland Delphi 6
BeitragVerfasst: So 19.06.05 14:22 
cool, dann bin ich hier der einzige der lesen kann :-).

Aber mal wieder zum Thema. Das mit der Stringzerlegung hatte ich auch schon gedacht. Aber das ist ziemlich kompliziert, da man dort schaltjahre, die verschiedenen tageszahlen der monate usw beachten muss.

Ich habe keine Ahnung, wie ich dass alles dort mit reinmachen soll.
The_Tremendous Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47

Win XP SP2
Borland Delphi 6
BeitragVerfasst: So 19.06.05 15:52 
Bin jetzt etwas weiter gekommen, allerdings rechnet er noch nicht richtig. Vielleicht findet ihr den fehler


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:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
procedure AnzahlTage;
var date1, date2 : string;
    tag1, tag2, monat1, monat2, jahr1, jahr2, i : integer;
    tagegesamt, monategesamt, jahregesamt, anzahlschalt, abgelaufeneTage : integer;
begin
  clrscr;
  anzahlschalt := 0;
  writeln('Bitte geben sie das erste Datum ein: '); readln(date1);
  writeln('Bitte geben sie das zweite Datum ein: '); readln(date2);

   tag1 := StrToInt(copy(date1,1,2));
   monat1 := StrToInt(copy(date1,4,2));
   jahr1 := StrToInt(copy(date1,7,4));

   tag2 := StrToInt(copy(date2,1,2));
   monat2 := StrToInt(copy(date2,4,2));
   jahr2 := StrToInt(copy(date2,7,4));

     // Berechnng der Jahre
     jahregesamt := jahr1 - jahr2;
      if jahregesamt <0 then begin
        jahregesamt := jahregesamt * -1
      end; writeln(jahregesamt);

     // Berechnung der Monate
     monategesamt := monat1 - monat2;
      if monategesamt <0 then begin
        monategesamt := Monategesamt + 12;
        jahregesamt:= jahregesamt-1;
      end; writeln(monategesamt);

      // Berechnung der Tage
      tagegesamt := tag1 - tag2;
       if tagegesamt <0 then begin
         tagegesamt := tagegesamt * -1;
       end; writeln(tagegesamt);

      // Prüfen auf Schaltjahre
      if jahr1 > jahr2 then begin
        for i := jahr1 to jahr2 do begin
          if i mod 4 = 0 then begin
            inc(anzahlschalt);
          end;
        end;
      end; writeln(anzahlschalt);

     // Tageszahl aus den Monaten berechnen
     case monategesamt of
      1:  abgelaufeneTage := tagegesamt;         // Monat Januar
      2:  abgelaufeneTage := 31 + tagegesamt;    // Monat Februar
      3:  abgelaufeneTage := 59 + tagegesamt;    // Monat März
      4:  abgelaufeneTage := 90 + tagegesamt;    // Monat April
      5:  abgelaufeneTage := 120 + tagegesamt;   // Monat Mai
      6:  abgelaufeneTage := 151 + tagegesamt;   // Monat Juni
      7:  abgelaufeneTage := 181 + tagegesamt;   // Monat Juli
      8:  abgelaufeneTage := 212 + tagegesamt;   // Monat August
      9:  abgelaufeneTage := 243 + tagegesamt;   // Monat September
      10: abgelaufeneTage := 273 + tagegesamt;   // Monat Oktober
      11: abgelaufeneTage := 304 + tagegesamt;   // Monat November
      12: abgelaufeneTage := 334 + tagegesamt;   // Monat Dezember
     end;  writeln(abgelaufeneTage); readln;
     tagegesamt := tagegesamt + abgelaufeneTage;  writeln(tagegesamt); readln;

     // Tageszahl plus die Tage resultierend aus den Jahren
     tagegesamt := tagegesamt + jahregesamt*365 + anzahlschalt;   writeln(tagegesamt); readln;

    write('Zwischen den beiden Daten '+date1+' und '+date2+ ' liegen ');
      write(tagegesamt);
        writeln(' Tage.');
    readln;


die ganzen ausgaben mittendrin habe ich halt für die tests eingeführt, lasst euch nicht dadurch stören.

Moderiert von user profile iconAXMD: Code- durch Delphi-Tags ersetzt.