Как получить дату, отправив название дня в функцию strtotime php - PullRequest
0 голосов
/ 22 апреля 2019

У меня есть название дня, я хочу получить только дату этой недели, используя это имя дня

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

эта функция возвращает дату следующего воскресенья.

мне нужнотолько настоящая неделя дата Как я могу получить, чтобы кто-нибудь помог мне заранее спасибо

Ответы [ 2 ]

0 голосов
/ 22 апреля 2019

Поскольку вы используете Laravel, вы можете воспользоваться библиотекой Carbon и использовать ее следующим образом:

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

// result 
// 28-04-2019
0 голосов
/ 22 апреля 2019
// 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; 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...