Getting end of month

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Getting end of month

Post by JKM »

Hi there,

I'm using mktime(0, 0, 1, $i, 1, $year), and I was wondering how I can find the unix time for 23:59:59 at the last day of the same month ($i).

Thanks.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Getting end of month

Post by Darhazer »

JKM wrote:Hi there,

I'm using mktime(0, 0, 1, $i, 1, $year), and I was wondering how I can find the unix time for 23:59:59 at the last day of the same month ($i).

Thanks.
You can use date('t') to find number of days. Or you can use the fact that if you pass negative number to mktime, it will go to the previous month correctly
mktime(23,59,59, $i+1, -1, $year)
Post Reply