Working on a mod where a user inputs a datetime in this format “11/28/2012 11:34 am”.
I am then using strtotime to convert it to a timestamp and saving it to my database.
I am then displaying it to the user in my template using the following date(DateTime, ‘D M jS g:i A’).
The problem is users who are not in the same timezone as the user who created the event do not get the correct time updated to reflect their timezone.
I have access to both timezone offset’s of the user posting and the user viewing.
MY question is how should I compensate for timezone differences?
When converting the string to the real timezone use this to override server time zone with time zone of the user submitting the value: https://www.php.net/manual/en/function.date-default-timezone-set.php
When retrieving it later, use the same function to override server time zone to current user’s one (the one that is appropriate for the user displaying datetime at the moment).
Also make sure you store it properly in the database: preferably using Unix timestamps within PHP, TIMESTAMP columns within database, FROM_UNIXTIME() database function when saving to the database and UNIX_TIMESTAMP() when retrieving from database (all are valid for MySql RDBMS, check your own DBMS if it is different).