如何通过将日期名称发送到strtotime函数php获取日期

时间:2019-04-22 10:53:46

标签: php laravel laravel-5

我有一天的名字,我只想使用该天的名字来获得这个星期的日期

date("d", strtotime('sun'));

此函数返回下一个星期天的日期。

我只需要当前的星​​期日期,我怎么能得到任何人的帮助我先谢谢

2 个答案:

答案 0 :(得分:0)

// PHP program to display sunday as first day of a week 

// l will display the name of the day 
// d, m and Y will display the day, month and year respectively 

// For current week the time-string will be "sunday -1 week" 
// here -1 denotes last week 
$firstday = date('l - d/m/Y', strtotime("sunday -1 week")); 
echo "First day of this week: ", $firstday, "\n"; 

// For previous week the time-string wil be "sunday -2 week" 
// here -2 denotes week before last week 
$firstday = date('l - d/m/Y', strtotime("sunday -2 week")); 
echo "First day of last week: ", $firstday, "\n"; 

// For next week the time-string wil be "sunday 0 week" 
// here 0 denotes this week 
$firstday = date('l - d/m/Y', strtotime("sunday 0 week")); 
echo "First day of next week: ", $firstday, "\n"; 

// For week after next week the time-string wil be "sunday 1 week" 
// here 1 denotes next week 
$firstday = date('l - d/m/Y', strtotime("sunday 1 week")); 
echo "First day of week after next week : ", $firstday; 

答案 1 :(得分:0)

由于您正在使用Laravel,因此可以利用Carbon库,并像这样使用它:

Carbon\Carbon::createFromFormat('D', 'Sun')->format('d-m-Y');

// result 
// 28-04-2019