Jump to content

changing date time to something other than where the server is located


webguync

Recommended Posts

Hello,

 

I am setting a date variable as this

$now = date("F j, Y, g:i a");

 

it displays the time as three hours difference from where I am, so I believe the server must be on west coast time and I am on east coast. I want to set the time three hours ahead. How can this be accomplished?

Try setting the timezone with date_default_timezone_set() at the start of your script (requires PHP >= 5.1.0). Timezone identifiers can be found here (to be used as the single parameter of mentioned function): http://dk2.php.net/manual/en/timezones.php

a little bit more on this. I need the timestamp to be entered into a field in my MySQL DB when form values are submitted,

 

I have the variable set as

 

$now = date('F j, Y, g:i a', strtotime('+3 hours'));

 

and the SQL is :

 

$insert = "INSERT INTO $check_table (`Assessor`,`AssessorID`,`EmpName`,`EmpID`, `Blocks`,`date_uploaded`) VALUES ('$Assessor','$Assessor_ID','$emp','$emp_id', '$blocks', '$now')";

 

the field column 'date_uploaded' is set as type 'datetime'

 

this worked before I added the strtotime('+3 hours') part. Did I need to make changes anywhere else to get the date to upload properly?

You should use an uppercase H (24-hour format) instead of the lowercase. Documentation: http://dev.mysql.com/doc/refman/5.0/en/datetime.html

 

<?php
$now = date('Y-m-d H:i:s', strtotime('+3 hours'));
?>

I agree. That was a typing mistake in my last post.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.