Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: Set time to CST

  1. #1
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts

    Set time to CST

    Good day!

    I'm having trouble setting the time to CST.

    I tried using:
    date_default_timezone_set('CST');

    ...but the manual says it only works on PHP 5, and when I tried:
    PHP Code:
    date_default_timezone_set('CST');
    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.

    Best Regards,
    Raymond.
    Last edited by rangana; 12-09-2008 at 12:50 AM.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,077
    Thanks
    2
    Thanked 320 Times in 312 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    rangana (12-08-2008)

  • #3
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Thanks for that. Should have ask the support earlier, meantime, I'll just stick to the JS.

    How about the "e" ?
    http://php.about.com/od/learnphp/ss/php_functions_3.htm

    Which says timezone could possibly be GMT,CST, etc...

    I'm not sure I understand that part.

    Please continue to guide.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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:
    PHP Code:
    <?php
    $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.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,077
    Thanks
    2
    Thanked 320 Times in 312 Posts
    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/functio...mezone-set.php
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    More importantly...http://us2.php.net/manual/en/timezones.php

    America/Chicago might be your best choice.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    rangana (12-09-2008)

  • #7
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Thanks for the input.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •