date/time issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

date/time issue

Post by bob_the _builder »

Hi,

I am using the following to set the time zone difference:

putenv("TZ=Pacific/Auckland");

But when I use now() on insert it places the server local time.

Is there a fix so it uses the above time zone?


Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

now() isn't a PHP function.
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Fair call, but putenv() is

Can you shift my post if its in the wrong place please?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

putenv() affects PHP only last I checked.
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

I guess it does, there away I can have it insert the correct date/time to my time zone?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Use date().
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

I have a php.ini file in my public_html folder to turn of register_globals etc, can I set my default time zsone in there?

Thanks
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post by maliskoleather »

thats what putenv(); does... sets your local timezone. but only in php. You could change it in the php.ini, but that would still only affect php. If you're working with a database, Its usually considered bad practice to use a timestamp generated by the database, because it wont nessicarally match up with the timestamp provided by php (or any other language).
always set your timestamps in a database using date(); or time();
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

The php.ini timezone value will only be used if the TZ environment variable is empty. putenv() should work, and if it doesn't, adjust the date.timezone directive in php.ini.
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Slow off the mark

I guess use:

Code: Select all

putenv("TZ=Pacific/Auckland");
then make date/time:

Code: Select all

$date = date('Y-m-d H:i:s');
then insert:

Code: Select all

$date
is the answer?


Thanks
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post by maliskoleather »

exactly.

though you dont nessicarily have to assign a variable.. you could just insert date();.. ie:

Code: Select all

$sql = "INSERT timestamp VALUES(".date('Y-m-d H:i:s').")";
and yes, i know the sql is bad/wrong/whatever. just an example :lol:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

php forum, database function now(), not specified which database system ...my guess ist: mysql ;)
If you want to set the timezone of a mysql server take a look at http://dev.mysql.com/doc/refman/4.1/en/ ... pport.html
olrac
Forum Newbie
Posts: 2
Joined: Wed May 23, 2007 1:13 am

Post by olrac »

Hello,

I have a question for this code is this the right bdate code?
because i tried these code and isn't working i mean it does but my age is 22. on that code it show my age is 23.

$dat=explode("-",$rs->fields[bdate]);
$age=(date("Y")- $dat[0]);

Thank you.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

@olrac
Before Post Read: General Posting Guidelines wrote:5. Do not hijack other people's threads, post your own topic and reference (i.e. link to) the other thread in it.
and you got answers in the other thread you've already hijacked.
Post Reply