Re: determine date range

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Dec 12, 2007 11:39 AM, slith <slithone@xxxxxxxxx> wrote:
> I'm working on hotel type booking script where prices will vary
> depending on the season. prices are updated every year so i need to take
> a user inputed date and determine which season the date falls under.
>
> i figured i can convert all dates into a timestamp and then run a series
> conditional statements to see which returns true.
>
> something like this:
>
> // date ranges
> $dates[1]['start'] = mktime(0, 0, 0, '01', '04', date('Y'));
> $dates[1]['end'] = mktime(0, 0, 0, '04', '14', date('Y'));
>
> $dates[2]['start'] = mktime(0, 0, 0, '04', '15', date('Y'));
> $dates[2]['end'] = mktime(0, 0, 0, '08', '18', date('Y'));
>
> $dates[3]['start'] = mktime(0, 0, 0, '08', '19', date('Y'));
> $dates[3]['end'] = mktime(0, 0, 0, '12', '23', date('Y'));
>
> $dates[4]['start'] = mktime(0, 0, 0, '12', '14', date('Y'));
> $dates[4]['end'] = mktime(0, 0, 0, '01', '03', date('Y') + 1);
>
> // tstamp is user inputed date
> if($tstamp >= $dates[1]['start'] && $tstamp <= $dates[1]['end']){
>         return 1;
> }
>
> if($tstamp >= $dates[2]['start'] && $tstamp <= $dates[2]['end']){
>         return 2;
> }
>
> if($tstamp >= $dates[3]['start'] && $tstamp <= $dates[3]['end']){
>         return 3;
> }
>
> if($tstamp >= $dates[4]['start'] && $tstamp <= $dates[4]['end']){
>         return 4;
> }
>
>
> now, not sure why this isn't working...but it's not returning true for
> any of these.
>
> also i'm realizing i need to account for people who decide to book a
> date a year ahead, in which case this approach will break since all
> timestamp date ranges (except for $date[4]['end']) are set to the
> current year.
>
> any suggestions on how i should approach this problem?
>
>
>
>

Will the boundary dates for each season change from one year to the
next? If so, I would probably store the seasons in a database table
and then just query from that table where the user-entered date is
between the season start and end dates. The table of seasons could
have dates configured as far out into the future as desired. If the
boundary dates are the same every year, you can ignore the year and
just compare the month/day of the user-entered date with the month/day
of the season boundaries.

Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux