esafwan
esafwan

Reputation: 18029

Easiest way to get the unix time stamp for the date exactly 1 month back in php

I want to get the unix time stamp for that day exactly 30days back from current day. What is the best method?

Can i use this to get the date 30 days back, is this the best method?

$day = date('Y-m-d', strtotime('-30 days'));

a google search brings me to mktime() function in php. But how do i combine both and get the unix time stamp for the day? What is the easiest and fastest method?

Upvotes: 3

Views: 5082

Answers (3)

ITroubs
ITroubs

Reputation: 11215

How to get previous month and year relative to today, using strtotime and date? watch this question. there is the discussion about the funny strtotime("-1 month"); bug.

Upvotes: 0

John Giotta
John Giotta

Reputation: 16944

$date = date_create();
date_sub($date, date_interval_create_from_date_string('1 m'));
echo date_format($date, 'U');

Upvotes: 1

Nick
Nick

Reputation: 6965

You just need to use the strtotime("-1 month"); function. That will return a UNIX timestamp.

Upvotes: 3

Related Questions