Page 1 of 1
date/time issue
Posted: Tue May 22, 2007 9:20 pm
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
Posted: Tue May 22, 2007 9:27 pm
by feyd
now() isn't a PHP function.
Posted: Tue May 22, 2007 9:32 pm
by bob_the _builder
Fair call, but putenv() is
Can you shift my post if its in the wrong place please?
Thanks
Posted: Tue May 22, 2007 9:36 pm
by feyd
putenv() affects PHP only last I checked.
Posted: Tue May 22, 2007 9:38 pm
by bob_the _builder
I guess it does, there away I can have it insert the correct date/time to my time zone?
Posted: Tue May 22, 2007 9:42 pm
by feyd
Posted: Tue May 22, 2007 10:28 pm
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
Posted: Tue May 22, 2007 11:22 pm
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();
Posted: Tue May 22, 2007 11:29 pm
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.
Posted: Wed May 23, 2007 12:26 am
by bob_the _builder
Slow off the mark
I guess use:
then make date/time:
then insert:
is the answer?
Thanks
Posted: Wed May 23, 2007 12:51 am
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

Posted: Wed May 23, 2007 5:57 am
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
Posted: Wed May 23, 2007 10:48 pm
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.
Posted: Wed May 23, 2007 10:59 pm
by volka
@olrac
and you got answers in the other thread you've already hijacked.