简体   繁体   English

php中给定日期的第一天

[英]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 : 为了获得给定月份的第一天,我已经使用了如上所述的strtotime ,但是我写道:

   $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'));

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"));

我希望它能起作用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM