Welcome to WebmasterWorld Guest from 54.225.58.238

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

racking my brain - php dates

     
10:44 pm on Jan 25, 2011 (gmt 0)

Junior Member

10+ Year Member

joined:July 22, 2005
posts:86
votes: 0


I've been trying to figure this one out, and I think my head is going to explode. I have 4 dates, that establish two parts to a year. Like this:

4/10 - 9/20 = Season 1
9/21 - 4/9 = Season 2

Then I have a date, and I need to figure out which Season it goes in.

For instance, 4/25 would go in season 1.

11/12 would go in season 2.

The years are not important.

I can't figure a way to approach this in PHP. My brain hurts! Please help!
10:50 pm on Jan 25, 2011 (gmt 0)

Moderator from US 

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 10, 2005
posts:5618
votes: 44


Option 1: Convert everything to dates and use the usual date comparison functions.

Option 2: Convert all the dates to a 4-character string (MMDD) (making sure you put leading zeros in the day or month <10) and do a simple string comparison.

In both cases, just test if between April 10 and Sept. 20. If so, it's season 1. Otherwise, it must be season 2.

(I don't know PHP, so I can't give you the specific functions or code to accomplish it, but this will hopefully point you in the right direction.)
10:58 pm on Jan 25, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 1, 2002
posts:1834
votes: 0


Convert to a timestamp. Easier to check the range I would think.
1:15 am on Jan 26, 2011 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 30, 2002
posts:4843
votes: 2


>timestamp

and/or ranges.. this PHP function may be useful to you, it takes dates in string format and converts them to a 4 byte UNIX timestamp.

[php.net...]