webguync Posted June 19, 2008 Share Posted June 19, 2008 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? Quote Link to comment Share on other sites More sharing options...
ober Posted June 19, 2008 Share Posted June 19, 2008 <?php echo strtotime("+3 hours"); ?> That's one approach. Quote Link to comment Share on other sites More sharing options...
webguync Posted June 19, 2008 Author Share Posted June 19, 2008 thanks ober. A little confused how I would integrate that with my variable though. $now = date("F j, Y, g:i a"); Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 19, 2008 Share Posted June 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
revraz Posted June 19, 2008 Share Posted June 19, 2008 I use a offset variable for my users can set their own timezone offset and just use <?php echo date('m/d/Y-H:i',($row->ndate + $offset)); ?> Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 19, 2008 Share Posted June 19, 2008 thanks ober. A little confused how I would integrate that with my variable though. <?php $now = date('F j, Y, g:i a', strtotime('+3 hours')); ?> Quote Link to comment Share on other sites More sharing options...
webguync Posted June 19, 2008 Author Share Posted June 19, 2008 that solution worked, Ober. Thanks! Quote Link to comment Share on other sites More sharing options...
webguync Posted June 19, 2008 Author Share Posted June 19, 2008 and thebadbad also Quote Link to comment Share on other sites More sharing options...
webguync Posted June 19, 2008 Author Share Posted June 19, 2008 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? Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 19, 2008 Share Posted June 19, 2008 try $now = date('Y-m-d h:i:s', strtotime('+3 hours')); Quote Link to comment Share on other sites More sharing options...
webguync Posted June 19, 2008 Author Share Posted June 19, 2008 ok, worked, Thanks! Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 20, 2008 Share Posted June 20, 2008 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')); ?> Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.