Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out what the date was 5 days ago?

Tags:

php

Well, the following returns what date was 5 days ago:

$days_ago = date('Y-m-d', mktime(0, 0, 0, date("m") , date("d") - 5, date("Y"))); 

But, how do I find what was 5 days ago from any date, not just today?

For example: What was 5 days prior to 2008-12-02?

like image 889
Yeti Avatar asked Apr 25 '10 16:04

Yeti


People also ask

How do you find the date of a day of the week from a date using PHP?

If your date is already a DateTime or DateTimeImmutable you can use the format method. $day_of_week = intval($date_time->format('w'));

What is Strtotime PHP?

The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.


1 Answers

I think a readable way of doing that is:

$days_ago = date('Y-m-d', strtotime('-5 days', strtotime('2008-12-02'))); 
like image 120
Mike Avatar answered Oct 01 '22 03:10

Mike