Home > Article > Backend Development > How to convert 30 days to timestamp in php
php method to convert 30 days into timestamp: 1. Create a php sample file; 2. Pass "mktime(0,0,0,date('m'),1,date('Y '));mktime(23,59,59,date('m'),date('t'),date('Y'));" can be used to obtain the start and end timestamps of this month.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
How to convert 30 days into timestamp in PHP?
First explain the format of the date() function:
date('Y-m-d',timestamp); //输出年-月-日 date('Y-m-d H:i:s',timestamp); //输出年-月-日 时:分:秒
php gets today’s date
date("Y-m-d",strtotime("today")); //strtotime('today')输出今天的开始时间戳
or
date("Y-m-d",time()); //time()输出当前的秒时间戳
php gets yesterday’s date
date("Y-m-d",strtotime("-1 day")); 或 date("Y-m-d",strtotime("yesterday"));
phpGet tomorrow's date
date("Y-m-d",strtotime("+1 day")); 或 date("Y-m-d",strtotime("tomorrow "));
phpGet the date 7 days later
date("Y-m-d",strtotime("+7 day"));
phpGet the date 30 days later
date("Y-m-d",strtotime("+30 day"));
phpGet the date one week later
date("Y-m-d",strtotime("+1 week"));
php Get the date one month later
date("Y-m-d",strtotime("+1 month"));
php Get the date one month ago
date("Y-m-d",strtotime("last month")); 或 date("Y-m-d",strtotime("-1 month"));
php Get the date one year later
date("Y-m-d",strtotime("+1 year"));
php Get the date one week, two days and four hours Time after five minutes and two seconds
date("Y-m-d H:i:s",strtotime("+1 week 2 days 4 hours 5 minute 2 seconds"));
php Gets the date of next Thursday
date("Y-m-d",strtotime("next Thursday"));
php Gets the date of last Monday
date("Y-m-d",strtotime("last Monday"));
php Gets the start and end timestamps of today
mktime(0,0,0,date('m'),date('d'),date('Y')); mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
php Gets the start and end timestamps of yesterday
mktime(0,0,0,date('m'),date('d')-1,date('Y')); mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
php Gets the start and end timestamps of last week
mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')); mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
php Gets the start and end timestamps of this month
mktime(0,0,0,date('m'),1,date('Y')); mktime(23,59,59,date('m'),date('t'),date('Y'));
Recommended study: " PHP video tutorial》
The above is the detailed content of How to convert 30 days to timestamp in php. For more information, please follow other related articles on the PHP Chinese website!