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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.