0

Ребят подскажите как преобразовать дату в виде "26 августа" в вид "2017-08-26" на PHP. Заранее спасибо!

3 ответа 3

4
function date2mysql($date) {
    $trans = [
        'января' => 'jan',
        'февраля' => 'feb',
        'марта' => 'mar',
        'апреля' => 'apr',
        'мая' => 'may',
        'июня' => 'jun',
        'июля' => 'jul',
        'августа' => 'aug',
        'сентября' => 'sen',
        'октября' => 'oct',
        'ноября' => 'nov',
        'декабря' => 'dec',
    ];
    return date("Y-m-d", strtotime(strtr($date, $trans)));
}    

echo date2mysql('26 августа');
0

Попробуйте так

<?php 

$full_date = '26 августа';

$month = substr($full_date,3);
$day = substr($full_date,0,2);


switch($month){
    case "января"   : $month = "01"; break;
    case "февраля"  : $month = "02"; break;
    case "марта"    : $month = "03"; break;
    case "апреля"   : $month = "04"; break;
    case "мая"      : $month = "05"; break;
    case "июня"     : $month = "06"; break;
    case "июля"     : $month = "07"; break;
    case "августа"  : $month = "08"; break;
    case "сентября" : $month = "09"; break;
    case "октября"  : $month = "10"; break;
    case "ноября"   : $month = "11"; break;
    case "декабря"  : $month = "12"; break;
}

$new_full = date('Y')."-".$month."-".$day;

echo $new_full;
2
  • а зачем здесь последняя строчка? 28 авг 2017 в 10:22
  • согласен, строка лишняя
    – kstkt
    28 авг 2017 в 13:37
-2

Вот так решил вопрос!

$video_time = '26 августа';
$day_old = explode(' ', $video_time);  
                $day_old = $day_old[1]; 
$video_date_month_old = end(explode(' ', $video_time)); 
                $video_game_year = date('Y');  
                if ($video_date_month_old == 'января') { $video_date_month = '01'; } 
                elseif ($video_date_month_old == 'февраля') { $video_date_month = '02'; } 
                elseif ($video_date_month_old == 'марта') { $video_date_month = '03'; } 
                elseif ($video_date_month_old == 'апреля') { $video_date_month = '04'; } 
                elseif ($video_date_month_old == 'мая') { $video_date_month = '05'; } 
                elseif ($video_date_month_old == 'июня') { $video_date_month = '06'; } 
                elseif ($video_date_month_old == 'июля') { $video_date_month = '07'; } 
                elseif ($video_date_month_old == 'августа') { $video_date_month = '08'; } 
                elseif ($video_date_month_old == 'сентября') { $video_date_month = '09'; } 
                elseif ($video_date_month_old == 'октября') { $video_date_month = '10'; } 
                elseif ($video_date_month_old == 'ноября') { $video_date_month = '11'; } 
                elseif ($video_date_month_old == 'декабря') { $video_date_month = '12'; }

$video_full_date = date("Y-m-d", strtotime($day_old.'-'.$video_date_month.'-'.$video_game_year));    

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.