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 4 of 4
  1. #1
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts

    Date Function Timezone Specification date("h:i A");

    I'm building a script that submits the time to the databse everytime a form is submitted. Is there a way to specify one specific timezone the time each time it submits?

    The format I'm using is,

    PHP Code:
    date("h:i A"); 

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Set the timezone at the top of the script, and all date/time functions
    will then use that timezone anywhere else in the script.

    Set timezone, and the list of timezone cities to use ...
    http://php.net/manual/en/function.da...mezone-set.php
    http://www.php.net/manual/en/timezones.php

    EDIT:
    Also, if it were me, I would simple write the UNIX timestamp (integer) into the column.
    That would allow you to later display it any way you wish, down to the seconds.

    $right_now=time();

    Which is at this value when I submitted this: 1296840028

    Later, you redisplay it like this:

    echo date("h:i A", $timestamp);


    .
    Last edited by mlseim; 09-01-2011 at 02:08 PM.

  • #3
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts
    If the variable is right_now why are you using timestamp? is that how the function is called?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I just made up the variable names.

    If you want to test out a snippet of code ... try this:
    PHP Code:
    <?php

    $right_now
    =time();

    echo 
    "The timestamp now is: $right_now <br />";

    echo 
    "Displaying that in a readable format: ".date("h:i A"$right_now);

    ?>


    .


  •  

    Posting Permissions

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