简体   繁体   中英

How to get the last days from a selected date?

How to get the last days from a selected date? Given:

$declation_date  = "2019-01-01"
$lastDays     = date('Y-m-t',$declation_date);

I want to display
$lastDays = 31;

You want to convert the date string to a unix timestamp using the strtotime() function , then use the date() function to convert that timestamp to a readable format, as you only want to get the last day of the month, just put the "t" format as it will display the total days of the month.

$declation_date = "2019-01-01";
echo date('t', strtotime($declation_date)); // outputs 31

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM