tclogo



HotelsCombined.com

Pages

Archives

Categories


Recent Postings

Recent Comments

Feeds

RSS2 feed

Links

Most Popular Posts

Recent Posting

Getting first and last day of the month

Saturday, 31st March 2007 11:30pm
Earlier today I was working on this form with two textboxes which had to initially show the first and last day of the current month respectively.


So I wanted a compact way of doing this using PHP without using a function or method and show the date in format d/m/yyyy. The first day of the month is straight forward and I could have used something simple like this:


$dtFirstDay = "1/" . date("m") ."/" . date("Y") ;


This could have done it but in the end I settled for a method with similar formulations for both first day and last day and hence:


$dtFirstDay = date("j/n/Y", mktime(0, 0, 0, date("m") , date("d")-date("d")+1, date("Y")));


and for last day:


$dtLastDay = date("j/n/Y", mktime(0, 0, 0, date("m")+1 , date("d")-date("d"), date("Y")));

delicious delicious | digg digg

Category: Php | Comments : 17