如何在PHP中获取当月的第一天? [重复]

时间:2021-08-02 23:44:38

This question already has an answer here:

这个问题在这里已有答案:

What I want to do is get 1st date of current month

我想要做的是获得当月的第一个日期

Here is how to get last day of the current month

以下是如何获取当月的最后一天

date('d-m-Y', strtotime('last day of this month'))

I've tried to use this, but it didn't work for me

我试过用它,但它对我没用

date('d-m-Y', strtotime('first day of this month'))    

Any idea how to solve my problem ?

知道怎么解决我的问题吗?

4 个解决方案

#1


130  

date('01-m-Y') should do it ;)

日期('01 -m-Y')应该这样做;)

#2


6  

date('d-m-Y', strtotime(date('Y-m-1')));

#3


3  

$firstDayUTS = mktime (0, 0, 0, date("m"), 1, date("Y"));
$lastDayUTS = mktime (0, 0, 0, date("m"), date('t'), date("Y"));

$firstDay = date("d-m-Y", $firstDayUTS);
$lastDay = date("d-m-Y", $lastDayUTS);

#4


2  

How about :

怎么样 :

date('1-m-Y',strtotime('this month'));

#1


130  

date('01-m-Y') should do it ;)

日期('01 -m-Y')应该这样做;)

#2


6  

date('d-m-Y', strtotime(date('Y-m-1')));

#3


3  

$firstDayUTS = mktime (0, 0, 0, date("m"), 1, date("Y"));
$lastDayUTS = mktime (0, 0, 0, date("m"), date('t'), date("Y"));

$firstDay = date("d-m-Y", $firstDayUTS);
$lastDay = date("d-m-Y", $lastDayUTS);

#4


2  

How about :

怎么样 :

date('1-m-Y',strtotime('this month'));