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? Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/ 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. Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569131 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"); Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569135 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 Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569138 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)); ?> Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569142 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')); ?> Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569150 Share on other sites More sharing options...
webguync Posted June 19, 2008 Author Share Posted June 19, 2008 that solution worked, Ober. Thanks! Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569186 Share on other sites More sharing options...
webguync Posted June 19, 2008 Author Share Posted June 19, 2008 and thebadbad also Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569217 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? Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569379 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')); Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569415 Share on other sites More sharing options...
webguync Posted June 19, 2008 Author Share Posted June 19, 2008 ok, worked, Thanks! Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569581 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')); ?> Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569976 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. Link to comment https://forums.phpfreaks.com/topic/110940-changing-date-time-to-something-other-than-where-the-server-is-located/#findComment-569991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.