|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Date Comparison problem
I wrote this script so that I could use if for one of my pages. Basically when you look at it, it is quite simple. Based on the DateAdd function of ASP, a user sets a particular date for an event to be displayed. If the current date is equal to the set date, the event will be displayed. if not, it will not be.
Everything seems to check out fine, the code and everything. but when i run it, i get this output: Selected Expiry Date: 10/07/2000 Current Date: 11/08/2002 Item Expiry Date: 11/07/2000 1 Clearly, here the current date is higher than the set date (item expiry date), so it should display "2", but it still displays "1". maybe i missed something somewhere, but I would be glad if anyone could have a look at the code blow and show me where my mistake is. Thanks, Emmanuel <?php function DateAdd ($interval, $number, $date) { $date_time_array = getdate($date); $hours = $date_time_array["hours"]; $minutes = $date_time_array["minutes"]; $seconds = $date_time_array["seconds"]; $month = $date_time_array["mon"]; $day = $date_time_array["mday"]; $year = $date_time_array["year"]; switch ($interval) { case "yyyy": $year +=$number; break; case "q": $year +=($number*3); break; case "m": $month +=$number; break; case "y": case "d": case "w": $day+=$number; break; case "ww": $day+=($number*7); break; case "h": $hours+=$number; break; case "n": $minutes+=$number; break; case "s": $seconds+=$number; break; } $timestamp = mktime($hours ,$minutes, $seconds,$month ,$day, $year); return $timestamp; } ?> <?php $curDate = date("d/m/Y"); $SelectedDate = $mine = strtotime("10 July 2000"); echo "Selected Expiry Date: " . date("d/m/Y", $SelectedDate), "n"; $ItemExpiryDate = DateAdd("d" ,1, $SelectedDate); echo "Current Date: " . ($curDate), "n"; echo "n"; echo "Item Expiry Date: " . date("d/m/Y", $ItemExpiryDate), "n"; echo "n"; ?> <?php if ($curDate <= $ItemExpiryDate) { echo "1"; } else { echo "2"; } ?> |
|
#2
|
|||||
|
|||||
|
RE: Date Comparison problem
I believe the answer is in the last code block:
php Code:
Cheers, Keith. |
|
#3
|
|||
|
|||
|
RE: Date Comparison problem
You know. I think you could make everything easier if you would base all dates on the epoch
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Date Comparison problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|