chadrt Posted January 18, 2013 Share Posted January 18, 2013 So I am developing some pages that show the time and use time and dates in the entries that will show in the database. I want to be able to simply change a database entry to something like -1 or +1 and have the hour of the date() that is being echoed update properly. I know how to call the entry in the database but I have been unsuccessfull in being able to change the date and time that is echoed based on that entrie. Examples: // This works <?php $offset = time() -3600; echo date("D, F jS g:i A",$offset); ?> // This pulls from the array because I can echo it $offsetquan = $thesetting['timezone']; // currently set to -1 So in the above example I can effectively remove one hour so how would I take the database entry of "-1" and multiply that by 3600 to make the time offset a true -1hr. from the database? My feeble attempt: lol <?php $zoneoffset = "-1"*3600; // this echo's properly! $offset = time() $zoneoffset; // this just kills the whole thing echo date("D, F jS g:i A",$offset); ?> In the example below it looks like a lot of work to get to where I am but I am trying work thru this in my head as I ask you all for help this helps me to see where I am attempting to go and lets you all know that I am really trying and not just seeking the quick fix. Thanks for the help by the way... <?php $test = -1; $zoneoffset = $test *3600; // this echo's properly! echo $zoneoffset; // see works well LOL $offset = time()-3600; // but if I try and put $zoneoffset in place of the -3600 it spits at me echo date("D, F jS g:i A",$offset); ?> Quote Link to comment https://forums.phpfreaks.com/topic/273302-add-or-subtract-from-the-date/ Share on other sites More sharing options...
Barand Posted January 18, 2013 Share Posted January 18, 2013 The MySql function SET datetimefield = NOW() - INTERVAL 1 HOUR SET datetimefield = NOW() + INTERVAL 1 HOUR will give current datetime plus or minus 1 hour Quote Link to comment https://forums.phpfreaks.com/topic/273302-add-or-subtract-from-the-date/#findComment-1406622 Share on other sites More sharing options...
chadrt Posted January 18, 2013 Author Share Posted January 18, 2013 I can see the usefullness of this particular entry but I also need to display my clock on the page with the correct time. This can't be done this way but thank you for the extra tid bit of info... Quote Link to comment https://forums.phpfreaks.com/topic/273302-add-or-subtract-from-the-date/#findComment-1406627 Share on other sites More sharing options...
Barand Posted January 18, 2013 Share Posted January 18, 2013 $offset = time() + $zoneoffset; Quote Link to comment https://forums.phpfreaks.com/topic/273302-add-or-subtract-from-the-date/#findComment-1406645 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.