Jump to content

Add or Subtract from the date()...


chadrt

Recommended Posts

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/273302-add-or-subtract-from-the-date/
Share on other sites

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.