There is a date in this format July 25, 2016, you need to get 2016-07-25 I do so

echo date("Ymd", strtotime($dbtArr[1])); 

I get 1970-01-01 03:00:00. What to do? I hope there is a way without explode and enumeration of synonyms for months.

  • 1970-01-01 03:00:00 is the starting point of the unixtime + 3 hours of the time zone. Those. strtotime could not recognize your date format. - ilyaplot
  • @Winteriscoming, do you keep the date 25 июль 2016 as a string? - Visman
  • @Visman, yes, this is a parser, on the page of the donor date in this format. - Winteriscoming

2 answers 2

Use this crutch:

 $dbtArr[1] = '25 июль 2016'; $dbtArr[1] = str_replace(array('январь', 'февраль', 'март', 'апрель', 'май', 'июнь', 'июль', 'август', 'сентябрь', 'октябрь', 'ноябрь', 'декабрь'), array('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'), $dbtArr[1]); echo date("Ymd", strtotime($dbtArr[1])); 

    Answer without explode and search for synonyms for months:

     <?php setlocale(LC_ALL, 'ru_RU', 'ru_RU.UTF-8', 'ru', 'russian'); echo strftime("%B %d, %Y", time()); 

    21st century: there is localization, and the correct analysis of the date and time.