12-08-2008, 02:11 PM
I'm having trouble setting the time to CST.
I tried using:
...but the manual says it only works on PHP 5, and when I tried:
echo date('n/t/Y g:i:s a');
...I'm getting an undefined error for date_default_timezone_set.
I'm not sure of how would I go about getting a CST time from the server.
I've had success on this on JS, but I prefer a server-side solution, but I'm out of my wits.
Please shed some light about my mistake.
12-08-2008, 02:28 PM
If you are still using php4, the end of life of php4 was one year ago this month. Your web host should have provided a way of switching your account to php5 long ago. Except for a very few minor cases, php4 code will work under php5, given the same exact php.ini configuration - http://us.php.net/manual/en/migration5.incompatible.php
If for some reason you cannot switch to php5, you will need to add logic in your code to add/subtract an offset to all functions that are date/time related to give the correct time zone.
BTW: CST is not a valid setting for date_default_timezone_set.
12-08-2008, 02:35 PM
Thanks for that. Should have ask the support earlier, meantime, I'll just stick to the JS.
How about the "e" ?
Which says timezone could possibly be GMT,CST, etc...
I'm not sure I understand that part.
Please continue to guide.
12-08-2008, 03:00 PM
I've found a fix, though it may not be "ideal", it's working at my end.
My server's time is just 2 hours ahead from CST time, so I've come up with this:
$hr = date('H')+2; // Get server's hour (24 hr format) and add 2
$hr = $hr>12?($hr-12):$hr; // If greater than 12, subtract by 12 otherwise keep it as is.
echo date('n/t/Y ').$hr.date(':i:s').($hr>12?' pm':' am'); // Outputs: date CST_Time am/pm
If you had better solution, please don't hesitate to let me know.
12-08-2008, 03:44 PM
How about the "e" ?
Just because a site like about.com posts an example that date('e') might give Ex: GMT, CST, does not mean that date_default_timezone_set('CST') is valid. Those sites are just reposting information from the php manual. It can be out of date, incomplete, or out of context. You should always make use the php manual directly. It is the most current, complete, and accurate source of php language information - http://us2.php.net/manual/en/function.date-default-timezone-set.php
12-08-2008, 05:26 PM
America/Chicago might be your best choice.