Wassim Sboui
Wassim Sboui

Reputation: 1820

The first day of a given date in php

to get the first day of a given month , i have used strtotime like above but it does'nt work i write :

   $d = date_parse_from_format("d-m-Y", $date);
   $month= $d["month"];
   $year=$d["year"];
   echo date("d-m-Y", strtotime('FIRST DAY OF $month $year'));

Upvotes: 0

Views: 405

Answers (2)

Andy
Andy

Reputation: 17771

The first day of this month can be expressed as

echo date('Y-m-01');

You can then extract further information from this if you require, for example the day of the week:

$month = '10';
$year  = '2012';
echo date('D', strtotime("{$year}-{$month}-01"));

Upvotes: 1

Mahdi
Mahdi

Reputation: 9417

I hope it works:

echo date("j", strtotime('FIRST DAY OF $month $year'));

Upvotes: 0

Related Questions