|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Oh Dear, comparing dates and times
I have two date and time routines which are giving me absolute murders at the moment and I don't understand why.
The first one I am using to check wether the day is a weekend or not. Keeps giving me the wrong number for the day.Why? Code:
Var
DayBand : Integer;
..............
CallDay := 12:27:03; //A saturday
DayBand := DayOfWeek(StrToDate(CallDay));
If (DayBand = 1) or (DayBand = 7) then
begin
CallBand := 'we_end';
end else
begin
If (TimeBandStart <= TimeOfCall1) and (TimeBandEnd >= TimeOfCall1) then Begin
CallBand := 'day';
end
else begin
CallBand := 'night';
end;
Just fixed the second problem. WhaDaYATink? |
|
#2
|
|||
|
|||
|
The Borland Documentation mentioned providing the date in US date format. In Fact it should be what your local PC date fromat is. So that sorted that out, but also my If else statements were wrong, in that I put an end; in the wrong place, which meant that some of my other code would only run inside the if else statement instead of outside of it.
Code:
CallDay := 27/12/03; //A saturday
DayBand := DayOfWeek(StrToDate(CallDay));
If (DayBand = 1) or (DayBand = 7) then
begin
CallBand := 'we_end';
end else
begin
If (TimeBandStart <= TimeOfCall1) and (TimeBandEnd >= TimeOfCall1) then Begin
CallBand := 'day';
end
else begin
CallBand := 'night';
end;
|
|
#3
|
||||
|
||||
|
It is probably better to use EncodeDate instead of using StrToDate to construct a DateTime object. That way, you can ensure that you get the correct Date/Time regardless of the locale settings.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month My Company is looking for a perl consultant for 3-4 months. Local to Los Angeles area preferred. PM me for details. Requirements |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Oh Dear, comparing dates and times |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|