First Day Of Month

First Day Of Month

Here is an often requested function to fetch the first day of the month. The function takes a single, optional parameter which is a unix timestamp of any date. The function will then return the unix timestamp of the first day of the month from the UNIX TIMESTAMP. If no timestamp is given, the function defaults to the current month.

The resulting timestamp can then be used with the PHP date() function to manipulated in any way possible. Ideal for calander classes or anywhere the first day of a month is required.


 * @ return timestamp of the first day of the month
 * @param INT Unix timestamp
 * @return INT
function firstDayOfMonth($uts=null)
$today is_null($uts) ? getDate() : getDate($uts);
$first_day getdate(mktime(0,0,0,$today['mon'],1,$today['year']));

/*** example usage ***/

 /*** using the default ***/
echo firstDayOfMonth();

'<hr />';

/*** using a timestamp ***/
$long_ago strtotime('April 16 2002');