I have been working on a project that requires the date for an online order to be within 3 days of the current date. As this is a WordPress project using Gravity Forms, it all sounded simple enough – use PHP to compare the selected date against the current date. However, I discovered that the date returned from PHP was wrong.
Yes, the time zone was current and it looked OK in phpinfo()
. But somehow, the date was 7 hours in the future!
WordPress came to my rescue. I used the function current_time('mysql')
which gave the correct date based on my dashboard settings. I then built a date without time so I could compare it to the date selected in the form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function isNotDateRange($date) { $notValid = false; $today=current_time('mysql'); list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = split( '([^0-9])', $today ); $today = mktime(0, 0, 0, $today_month, $today_day,$today_year); $compDate = strtotime("+3 days", $today); $currDate = strtotime($date); if ($currDate < $today || $currDate > $compDate) { $notValid = true; } return $notValid; } |
-0 Comments