Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-01-2011, 05:50 AM   PM User | #1
stevenmw
Regular Coder

 
stevenmw's Avatar
 
Join Date: Jun 2007
Location: OK
Posts: 449
Thanks: 26
Thanked 30 Times in 30 Posts
stevenmw is an unknown quantity at this point
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"); 
stevenmw is offline   Reply With Quote
Old 09-01-2011, 12:32 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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..
mlseim is offline   Reply With Quote
Old 09-02-2011, 07:56 AM   PM User | #3
stevenmw
Regular Coder

 
stevenmw's Avatar
 
Join Date: Jun 2007
Location: OK
Posts: 449
Thanks: 26
Thanked 30 Times in 30 Posts
stevenmw is an unknown quantity at this point
If the variable is right_now why are you using timestamp? is that how the function is called?
stevenmw is offline   Reply With Quote
Old 09-02-2011, 12:20 PM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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);

?>


.
mlseim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:20 PM.


Advertisement
Log in to turn off these ads.