Я хочу получить дату прошлого месяца. Я выписал это:
$prevmonth = date('M Y');
Который дает мне текущий месяц/год. Я не могу сказать, должен ли я использовать strtotime
, mktime
. Что-то к метке времени? Я должен добавить что-то впоследствии для сброса так, чтобы дата не была назначена к прошлому месяцу всюду по всему для всех меток времени на моем сайте? Я пробую к RTM, но мне трудно понять это.
Oh I figured this out, please ignore unless you have the same problem i did in which case:
$prevmonth = date("M Y",mktime(0,0,0,date("m")-1,1,date("Y")));
You can use strtotime
, which is great in this kind of situations :
$timestamp = strtotime('-1 month');
var_dump(date('Y-m', $timestamp));
Will get you :
string '2009-11' (length=7)
echo strtotime("-1 month");
That will output the timestamp for last month exactly. You don't need to reset anything afterwards. If you want it in an English format after that, you can use date() to format the timestamp, ie:
echo date("Y-m-d H:i:s",strtotime("-1 month"));