Date comparrison function problems for calendar

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   Date comparrison function problems for calendar
harknell
CZ Newbie
harknell has been a member for over 19 year's 19 Year Member
Gender: Male
Status: Offline
Joined: Sep 19, 2005
0.00 posts per day
Posts: 18
Points: 653
   
Ok, I'm writing a function to determine if a submitted calendar date is already entered into a database, or if a time range is within a time range already entereed in the database.

The time is setup as the typical 2005-12-02 23:00:00 24 hour time format. I need to be able to take 2 dates and compare if one date is before or after the other date. I obviously can't just use the < > operators since these are strings and not plain numbers. I believe that I can use the function strtotime on the dates to convert them to a timestamp, which is then just a big number, which can then be simply compared using math operators. If I use strtotime($time), with $time being a time string like the one I listed above, will that simply convert the time listed into a numerical string related to the Unix epoch? If I do that to both $time and a new time $newtime, can I then just compare them with < > = and be assured that it will work?

Also, say I have a duration of hours and minutes that I need to add to both of these variables to get when the event ended (so it starts at 12 oclock and ends at 2 oclock...so 2 hours added), can I use strtotime to relate this new time? I believe you do that by doing something like strtotime( + $durationhours hours, $time) which is essentially saying "use $time as your base, then add the variable $durationhours number of hours onto this, then return as a unix timestamp"....is this correct? Do I need "" marks or '' anywhere around the variables or the plain text elements in the strtotime function? I tried reading up on this but it's sort of confusing. I think I'm right, but I keep getting errors when I try this out in my script.



Back to top Reply with quote
#2   Re: Date comparrison function problems for calendar
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,475
   


Originally posted by harknell @ Fri Dec 02, 2005 11:32 am:

Ok, I'm writing a function to determine if a submitted calendar date is already entered into a database, or if a time range is within a time range already entereed in the database.

The time is setup as the typical 2005-12-02 23:00:00 24 hour time format. I need to be able to take 2 dates and compare if one date is before or after the other date. I obviously can't just use the < > operators since these are strings and not plain numbers. I believe that I can use the function strtotime on the dates to convert them to a timestamp, which is then just a big number, which can then be simply compared using math operators. If I use strtotime($time), with $time being a time string like the one I listed above, will that simply convert the time listed into a numerical string related to the Unix epoch? If I do that to both $time and a new time $newtime, can I then just compare them with < > = and be assured that it will work?

Also, say I have a duration of hours and minutes that I need to add to both of these variables to get when the event ended (so it starts at 12 oclock and ends at 2 oclock...so 2 hours added), can I use strtotime to relate this new time? I believe you do that by doing something like strtotime( + $durationhours hours, $time) which is essentially saying "use $time as your base, then add the variable $durationhours number of hours onto this, then return as a unix timestamp"....is this correct? Do I need "" marks or '' anywhere around the variables or the plain text elements in the strtotime function? I tried reading up on this but it's sort of confusing. I think I'm right, but I keep getting errors when I try this out in my script.


Yes and Yes. What errors do you receive?




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#3   re: Date comparrison function problems for calendar
harknell
CZ Newbie
harknell has been a member for over 19 year's 19 Year Member
Gender: Male
Status: Offline
Joined: Sep 19, 2005
0.00 posts per day
Posts: 18
Points: 653
   
Luckily I've made it past this point. The errors I was getting referred to the fact that I was using 24 hour time, but because it was based on a "human" model of showing it (1-24), it caused a strtotime error since strtotime wants a computer 24 hour time (0-23) input. So midnight was blowing up. and since that's the "default" for display I couldn't figure out why the problems were occuring.



Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum