Autor Beitrag
chrizz_15
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Mo 05.04.04 08:34 
Hallo!

:arrow: Ich hab ein MaskEdit und kann da natürlich auch wunderbar das aktuelle Datum eingeben lassen:
ausblenden Quelltext
1:
MaskEdit1.Text := DateToStr(Now);					

Diesen String speicher ich dann in einer Datenbank (per SQL)...

:?: Jetzt möchte ich aber zu dem Datum aus dem MaskEdit gerne einen, oder zwei, oder n-Tage "addieren". Habt ihr eine Lösungsidee?
Stauch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 140

Win 2000, Win XP
D4
BeitragVerfasst: Mo 05.04.04 08:40 
Hallo,

mit der Prozedur
ausblenden Delphi-Quelltext
1:
procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);					


kannst Du das Datum in die einzelnen Bestandteile zerlegen und dann einzeln bearbeiten.

Viel Spaß beim Basteln

Carsten

_________________
Geht das? Und wenn ja, warum nicht?
chrizz_15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Mo 05.04.04 09:01 
ich kann mit der funktion irgendwie nich wirklich was anfangen :?
was für variablen brauche ich da und welches datum verändere ich? vielleicht mal ein beispiel? z. b. das heutige datum + 3 tage. wenn das geht?
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Mo 05.04.04 09:15 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
function DatumPlusMinusTage(s: string; Tage: integer): TDate; 
begin 
  result := strtodate(s) + Tage; 
end; 
 
function DatumPlusMinusMonate(s: string; Monate: integer): TDate; 
begin 
  result := incmonth(strtodate(s), Monate); 
end; 
 
function DatumPlusMinusJahre(s: string; Jahre: integer): TDate; 
var tag, monat, jahr: word; 
begin 
  decodedate(strtodate(s), jahr, monat, tag); 
  inc(jahr, Jahre); 
  result := encodedate(jahr, monat, tag); 
end;


Hier ein Beispiel für die Umsetzung
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button3Click(Sender: TObject); 
begin   
showmessage(datetostr(datumplusminusjahre('05.04.04', 3))); 
 end;


Mußt eigentlich nur deinen Wert übergeben den du für dein Datum hast.

Gruß
tmc

_________________
it's not a bug it's a feature
Aton
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 125

Windows XP
D7 Enterprise
BeitragVerfasst: Mo 05.04.04 09:16 
Wie wäre es mit

Edit.Text := DateToStr(Now+3);

edit: Ach, dass Datum kommt aus der Datenbank? Dann vergiß meinen Beitrag...

Gruß Jens.
chrizz_15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Mo 05.04.04 09:26 
@ Aton

:D :D :D

:arrow: Super geniale einfach Lösung mit einem gigantischen Vorteil: die Montats- und Jahresumstellung, wenn der z. B. die Tageszahl 40 ist geht automatisch weiter 8)

Danke;-)

Nachtrag: wieso vergessen? das datum wird erst als string in die datenbank übergeben. das is ok.
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Mo 05.04.04 09:40 
Ist das nicht das selbe was ich in meiner Funktion geschrieben hab? Naja dachts du brauchst das ganze variabler.

Gruß
tmc

_________________
it's not a bug it's a feature
chrizz_15 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Mo 05.04.04 09:48 
tmc2004 hat folgendes geschrieben:
Ist das nicht das selbe was ich in meiner Funktion geschrieben hab?


:idea: Ja es ist eigentlich sogar identisch. Nur eben kürzer. Und da mein Programm so klein wie möglich sein muss ist das für mich vorteilhafter. 8)
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Mo 05.04.04 09:58 
Naja kommt ja immer drauf an wie oft man etwas verwendet. :wink:

Gruß
tmc

_________________
it's not a bug it's a feature