#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13

    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    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;
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo