Feeds:
Posts
Comments

Posts Tagged ‘php 5.3’

This month’s date range

I noticed that many people search for ‘this month’s date range’. The trick lies in knowing which month you want to go to and that mktime can automatically find the end of the month by passing 0 into the day field.

Well in no short order here it is:

// casting as date object, otherwise it returns a unix timestamp
$first_of_this_month = date('m/d/y',mktime(0,0,0,date('m'),1,date('y')));
$end_of_this_month = date('m/d/y',mktime(0,0,0,date('m')+1,0,date('y')));

// if run on 4/01/11
var_dump($first_of_this_month,$end_of_this_month);
// outputs
// string(8) "04/01/11"
// string(8) "04/30/11"

Read Full Post »

Design a site like this with WordPress.com
Get started