且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从日期找到一个月的最后一天?

更新时间:2022-11-13 15:31:06

t 返回给定日期的月份天数(见 日期的文档 ):

  $ a_date =2009-11-23; 
echo date(Y-m-t,strtotime($ a_date));


How can I get the last day of the month in PHP?

Given:

$a_date = "2009-11-23"

I want 2009-11-30; and given

$a_date = "2009-12-23"

I want 2009-12-31.

t returns the number of days in the month of a given date (see the docs for date):

$a_date = "2009-11-23";
echo date("Y-m-t", strtotime($a_date));