Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 5th, 2004, 12:49 PM
lloydie-t lloydie-t is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2002
Location: UK
Posts: 521 lloydie-t User rank is Private First Class (20 - 50 Reputation Level)lloydie-t User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 16 h 42 m 8 sec
Reputation Power: 7
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?

Reply With Quote
  #2  
Old January 5th, 2004, 03:13 PM
lloydie-t lloydie-t is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2002
Location: UK
Posts: 521 lloydie-t User rank is Private First Class (20 - 50 Reputation Level)lloydie-t User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 16 h 42 m 8 sec
Reputation Power: 7
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;

Reply With Quote
  #3  
Old January 15th, 2004, 12:09 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,533 Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 5 h 55 m 9 sec
Reputation Power: 876
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Oh Dear, comparing dates and times


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway