Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the last day of the month from date?

Tags:

date

php

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.

like image 201
Mithun Sreedharan Avatar asked Nov 06 '09 10:11

Mithun Sreedharan


People also ask

How do you find the last date of the month in Excel?

Use a formula to find the end date of each month may be very easy for every Excel user. Also, you can use this formula =EOMONTH(A2,0) to get the month's end date.

How do I find the end date of a date?

Subtract Dates in Excel To find the number of dates between the start date and end date, use this formula in cell C2: =B2-A2.


1 Answers

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)); 
like image 173
Dominic Rodger Avatar answered Oct 08 '22 04:10

Dominic Rodger