Autor Beitrag
tortom1000
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175

Win XP, Win Server 2003 - 2012, Win 7
Delphi 7
BeitragVerfasst: Do 14.01.10 17:52 
Hallo,
wie kann ich überprüfen, ob sich mein aktuelles Systemdatum und -zeit zwischen zwei Vorgaben befindet,
die mittels zwei DateTime.Picker'n vorgegeben wurden.
Viele Grüße zum neuen Jahr
Tortom
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Do 14.01.10 17:55 
Aktuelle Datum / Uhrzeit bekommst du mit now.
Wert von einem DateTimePicker.. glaub .Value oder .DateTime?
Vergleichen mit > und <

Nun puzzel zusammen :D

_________________
PROGRAMMER: A device for converting coffee into software.
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 14.01.10 17:56 
da datum und zeit eine doublevariable sind kannst du einfach das mit kleiner / größer vergleichen.

ausblenden Delphi-Quelltext
1:
2:
if (datetimepicker1.datetime < now) AND (datetimepicker2.datetime > now) then
  DoSomething;


lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
tortom1000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175

Win XP, Win Server 2003 - 2012, Win 7
Delphi 7
BeitragVerfasst: Do 14.01.10 19:44 
Vielen Dank.

Mit eurer Hilfe habe ich mein Problem hinbekommen.

Tortom
tortom1000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175

Win XP, Win Server 2003 - 2012, Win 7
Delphi 7
BeitragVerfasst: Mi 27.01.10 20:32 
Hallo liebe Delphi-Gemeinde,
mein Problem ist doch noch nicht ganz gelöst.

Die Bedingung, die Elundril vorgeschlagen hat, funktioniert leider nicht.

Es geht darum, zu prüfen, ob der jetzige Zeitpunkt, welcher aus Datum und Zeit besteht zwischen zwei Vorgaben liegt,
welche ebenfalls aus Datum und Zeit bestehen.

Beispiel:
DateTimePicker1: 10.01.2010 12:00 Uhr
DateTimePicker2: 09.01.2010 14:00 Uhr
Prüfzeitpunkt: 10.01.2010 15:00 Uhr -> Der Prüfzeitpunkt liegt nicht innerhalb der beiden Vorgabezeitpunkte,
also darf die Bedingung nicht erfüllt sein.
Tatsächlich ist sie jedoch trotzdem erfüllt.

Weiß jemand, warum?
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mi 27.01.10 21:09 
Wie sieht denn dein Versuch aus ?
tortom1000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175

Win XP, Win Server 2003 - 2012, Win 7
Delphi 7
BeitragVerfasst: Mi 27.01.10 21:32 
Hi,
mittlerweile habe ich 2 DateTimePicker fürs Datum sowie 2 für die Uhrzeit.

Zuerst prüfe ich auf's Datum, danach auf die Uhrzeit.


if ((form1.datetimepicker1.date <= now) and (form1.datetimepicker2.date >= now)) then
begin
if (form1.datetimepicker11.time < now) and (form1.datetimepicker22.time > now) then showmessage('innerhalb des Zeitrahmen');
end
else showmessage('ausserhalb des Zeitrahmen');

(mir ist klar, das wenn das Datum OK ist, aber die Uhrzeit des datetimepicker22 kleiner als now ist, es zu keiner Meldung kommt. Die Abfragen
habe ich nur zum Testen... gestrickt)

Funktioniert aber trotzdem nicht. Keine Ahnung, wo da der Fehler ist.

Ich habe die DateTimePicker fürs Datum als dtkDate deklariert, entsprechend die anderen beiden für die
Zeit mit dtkTime.

Im OnCreate formatiere ich sie mir folgendermaßen:
DateTimePicker1.Format := 'dd:MM:yyyy';
DateTimePicker11.Format := 'HH:mm';
DateTimePicker11.Time := now;
DateTimePicker1.Date := now;
DateTimePicker2.Format := 'dd:MM:yyyy';
DateTimePicker22.Format := 'HH:mm';
DateTimePicker22.Time := now;
DateTimePicker2.Date := now;

Bin für Hilfe dankbar...

Tortom
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mi 27.01.10 22:59 
Warum nicht einfach nen Picker für datum und Uhrzeit zusammen?

Wenn du das unbedingt so haben möchtest: Setz halt nen Haltepunkt, und schau dir die Werte im Debugger an.

_________________
PROGRAMMER: A device for converting coffee into software.
tortom1000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175

Win XP, Win Server 2003 - 2012, Win 7
Delphi 7
BeitragVerfasst: Mi 27.01.10 23:39 
Ich hatte ursprünglich 'nen Picker für Datum und Uhrzeit zusammen, was nicht funktioniert hat.
Die Trennung von Datum und Uhrzeit dient lediglich der besseren Analyse, was da querschießt...

War der Tipp von Elundril:
if (datetimepicker1.datetime < now) AND (datetimepicker2.datetime > now) then ...
DonManfred
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148
Erhaltene Danke: 2

Windows 7
Delphi XE3 Pro + HTML5Builder
BeitragVerfasst: Do 28.01.10 20:18 
Nimm die DateUtils und Types in deine unit mit auf... In DateUtils findest Du ne Menge funktionen die zwei tdatetime als parameter brauchen...

kleines Beispiel...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var a, b: tdatetime;
begin
  if CompareDateTime(a,b) = LessThanValue then ShowMessage('a ist kleiner');

  if CompareDateTime(a,b) = GreaterThanValue then ShowMessage('b ist kleiner');

  if CompareDateTime(a,b) = EqualsValue then ShowMessage('a und b sind gleich');
end;


ausblenden Delphi-Quelltext
1:
if (CompareDateTime(datetimepicker1.datetime,now) = LessThanValue) AND (CompareDateTime(datetimepicker1.datetime,now) = GreaterThanValue) then ...					

_________________
Gruss Manfred
tortom1000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 175

Win XP, Win Server 2003 - 2012, Win 7
Delphi 7
BeitragVerfasst: Sa 30.01.10 09:16 
Hallo,
wollte euch noch den "finalen" Stand mitteilen.
Mein Fehler war, das ich die ganze Sache zu einfach angegangen bin.

Ich hab's nun folgendermaßen gemacht:

Mittels trunc (->Vorkommawert) das "reine" Datum, mittels frac
(->Nachkommawert) den Zeitanteil der DateTimePickerX.Date ermittelt.
Gleiches habe ich mit "Now" gemacht.
Mit diesen Werten habe ich nun "verglichen" und dann funktionierte
auch alles.

Vielen Dank nochmals für eure Hilfe
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Sa 30.01.10 16:40 
Wenn ich ein Datum mit Float Wert 1234,5 habe, und eins mit Wert 1235,3
und jetzt gerade ist 1234,6
dann liegt das zwischen den beiden Werten. Wozu die Aufteilung in Datum und Tag? Zeig bitte nochmal den Quellcode..

_________________
PROGRAMMER: A device for converting coffee into software.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 30.01.10 21:39 
user profile iconXentar hat folgendes geschrieben Zum zitierten Posting springen:
Wenn ich ein Datum mit Float Wert 1234,5 habe, und eins mit Wert 1235,3
und jetzt gerade ist 1234,6
dann liegt das zwischen den beiden Werten. Wozu die Aufteilung in Datum und Tag? Zeig bitte nochmal den Quellcode..


Wie Xentar sagt, die ganze Sache liegt wahrscheinlich an dir bzw. deinen Quellcode den das hier sollte eigentlich auch funktionieren.


user profile iconelundril hat folgendes geschrieben Zum zitierten Posting springen:
da datum und zeit eine doublevariable sind kannst du einfach das mit kleiner / größer vergleichen.

ausblenden Delphi-Quelltext
1:
2:
if (datetimepicker1.datetime < now) AND (datetimepicker2.datetime > now) then
  DoSomething;


lg elundril