A
A
Anton2018-10-11 17:20:04
PHP
Anton, 2018-10-11 17:20:04

How to get day and month by converting variable in php?

echo $rusdate; // выведет ПТ 18:00 или СР 12:00 и тому подобное, по сути это текстовая строка

How to get the date of the current week in this form:
12 октября к 18:00
i.e. it is necessary to determine that Fri 18:00 is Friday, and Friday this week is October 12.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2018-10-11
@anton99zel

You can get the time of, say, Monday this week via relative time format strtotime('monday this week'); (English only)

$rusdate='ПТ 18:00';
list($dow, $hours, $minutes) = sscanf($rusdate, "%s %d:%d");

$rusweek = explode(',','ВС,ПН,ВТ,СР,ЧТ,ПТ,СБ');
$ndow = array_search($dow, $rusweek);

date_default_timezone_set('Europe/Moscow'); // если не настроен PHP
$time = strtotime('monday this week') + 86400 * $ndow + 3600 * $hours + 60 * $minutes;
echo date('Y-m-d H:i:s', $time);
// 2018-10-13 18:00:00

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question