Date in words in PHP

Good day to all.

There are 3 variables in the page: $dd, $mm, $YYYY, which are already equal to the day, month, and year in advance. I wanted to output the date in words with the values of the variables. I didn't find anything short on the Internet, or rather, I didn't find anything there at all. In principle, you can write code with pens, but if you list the numbers of the day and year in order, it will be very long.

Maybe someone has a solution for displaying the date in words? Please share.

 0
php
Author: Nicolas Chabanovsky, 2011-08-18

3 answers

Google has everything. Here is an example for months

function russian_date(){
$date=explode(".", date("d.m.Y"));
switch ($date[1]){
case 1: $m='января'; break;
case 2: $m='февраля'; break;
case 3: $m='марта'; break;
case 4: $m='апреля'; break;
case 5: $m='мая'; break;
case 6: $m='июня'; break;
case 7: $m='июля'; break;
case 8: $m='августа'; break;
case 9: $m='сентября'; break;
case 10: $m='октября'; break;
case 11: $m='ноября'; break;
case 12: $m='декабря'; break;
}
echo $date[0].' '.$m.' '.$date[2];
}
russian_date();

Another option

<?php
    // Установливаем русскую локаль
    // или setlocale(LC_ALL, 'ru_RU'); в PHP 4
    setlocale(LC_ALL, 'rus_RUS');
    // Получаем сегодняшнюю дату
    // Формируем вывод
    // %a - короткая запись дня недели (Чт)
    // %A - обычная запись дня недели (Четверг)
    // %Y - год полностью (2008)
    // %y - год кратко (08)
    // Короче, смотрите маны
    $data = strftime("%a, %d/%m/%Y", time());
    // В PHP4 потребуется конвертация
    // $data = iconv('ISO-8859-5','windows-1251', $data);
    echo $data; // В PHP 4 название дня недели
    // будет начинаться с заглавной буквы
    // в обычной форме записи
?>
 3
Author: Kenpachi, 2011-08-18 12:28:46
function date_rus($d, $m, $y) {
    $months = array('нулября', 'января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');
    return $d . ' ' . $months[$m] . ' ' . $y . ' года';
}
 1
Author: const_se, 2011-08-19 02:51:43

Here is an article on working with dates in MySQL. There at the end is just how to get the date of the registration, and without unnecessary problems.http://myshinobi.ru/rabota-s-datami-v-mysql/

 0
Author: Shinobi, 2014-11-22 16:49:47