Jump to content

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


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

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.