Jump to content

Todays time and date + and - five days with PHP


oskare100

Recommended Posts

Hello,
When the scripts requests from the Ebay API it need to supply the current time and date plus five days and minus five days.

It needs to be in this format: 2007-01-17T18:28:52.799Z
So if now is 2007-01-20 18:28:52 then I need he script to create two variables with the following values;
(Minus five days) $time_from = 2007-01-15T18:28:52.799Z
(Plus five days) $time_to: = 2007-01-25T18:28:52.799Z

How can I make PHP add minus five days to, for example, $time_from and plus five days to, for example, $time_to as above?

Thanks in advance,
/Oskar R
Link to comment
Share on other sites

It'd probably be easiest to use the unix time stamp format returned by the time() function, and store that in the variables, and then using the date() function to restore it to a readable format however you want it displayed.

Unix timestamp is the amount of time in seconds that have gone by since January 1, 1970.  So to get the timestamp from 5 days ago, you would subtract 60*60*24*5 from the current time, and to get the timestamp for 5 days in the future, you would add this.

[code]
$current=time();
$fiveago=time()-(60*60*24*5);
$fiveahead=time()+(60*60*24*5);
[/code]

Then to retrieve the values you would use the date function

[code]
echo date("M jS, Y", $fiveago);
echo date("M jS, Y", $fiveahead);
[/code]
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.