I have a form where the user will enter a date and time for an email campaign. As part of the form validation, I am confirming that the user enters a future date.
The current servers default time zone is UTC.
The user will enter the scheduled date and time as a string (generated by a JQuery date and time picker).
The entered string is converted to a timestamp, and then compared with the current date and time.
If the entered date & time is before the current date & time, the form is not submitted and the user is notified to re-enter a future date.
The problem is, if the user enters a future time & date and time within the next 8 hours of the current time (which is pacific time zone), the system will think it's in the past because the server time zone is UTC (which is 8 hours ahead of PST).
I tried to convert the user input to UTC using gmdate like below:
//$timeEntered is a string, like 2015/11/06 19:27:21:
$timeEntered = $_POST['date_and_time']
$theEnteredTimeInUnixTimestamp = strtotime ( $timeEntered );
$enteredTimeInGMT = gmdate('Y-m-d H:i:s', $theEnteredTimeInUnixTimestamp );
but it won't convert it. Should I just add 8 hours to the entered date and time so it matches the current server time (UTC)? That would be stupid because this will change during daylight savings time.
Should I change the current server time zone to Pacific time while doing the comparison, so the time zones match? That will give unexpected results if the users are in different time zones. I'm not sure how to handle this to make it reliably compare the entered time with the current time and give a correct result.