Jump to content

What function to use to get the first day of the month ?


jd2007

Recommended Posts

date and strtotime, eg:

 

// date for the 1st of december 2007
$date = '01-12-2007';

// convert date into a timstamp
$date_timestamp = strtotime($date);

// get the day
$day = date('l', $date_timestamp);

echo $day;

Here's how to get the first day of the current calendar month:

<?php
$day_of_week = date("l", mktime(0, 0, 0, date('n'), 1, date('Y')));
echo $day_of_week;
?>

 

For August 2007, output is "Wednesday".

 

See http://stephen.calvarybucyrus.org/misc/first_day_of_month.php

Wildteen,

 

Alas, strtotime() does not recognise d/m/y or d-m-y

 

<?php
// date for the 1st of december 2007
$date = '01-12-2007';

// convert date into a timestamp
$date_timestamp = strtotime($date);

// now back to date again
echo date ('Y-m-d', $date_timestamp);  //  1970-01-01

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.