How to subtract 4 months from today's date?

Jason94 picture Jason94 · Nov 12, 2010 · Viewed 48.5k times · Source

I need to declare two dates in "Ymd" format: $toDate and $fromDate.

$toDate represents today's date and $fromDate needs to be 4 months earlier than today.

$toDate = Date('Ymd');
$fromDate = ?

How do I create $fromDate?

Answer

Pekka picture Pekka · Nov 12, 2010

Use the magic of strtotime:

$fromDate = date("Ymd", strtotime("-4 months"));