In the database, the value is stored in the DATE format: 2014-07-20 How can you get the month value in abbreviated form in PHP?

    2 answers 2

    Choose what you want:

    $time = strtotime('2014-07-20'); echo 'Месяц (сокращенное название) - '.date('M', $time).'<br>'; // Jul echo 'Месяц (полное название) - '.date('F', $time).'<br>'; // July echo 'Номер месяца c ведущим нулем - '.date('m', $time).'<br>'; // 07 echo 'Номер месяца без ведущего нуля - '.date('n', $time).'<br>'; // 7 

      Did you read the date() function documentation?

      M Сокращенное наименование месяца, 3 символа от Jan до Dec

      • It is necessary to obtain from the date 2014-07-20, and not from the current date - Jony
      • one
        @Oleg Ponomarchuk - read the CAREFULLY documentation, which says:> The second parameter of the function int $timestamp = time() . The timestamp specified by the timestamp argument or the current system time is used if the timestamp not set. Thus, the timestamp is optional and defaults to the value returned by the time() function. - Opalosolo
      • It can be like this: date ("M", mktime (0, 0, 0, $ exp [2], $ exp [1], $ exp [0])); - Jony
      • @Oleg Ponomarchuk - if you don’t know how to get the timestamp tag from the date 2014-07-20, then the strtotime () function will help you - Opalosolo
      • one
        @Oleg Ponomarchuk - why do you write 'd - m - Y' if you need to get the name of the month? I gave the link to the code above. - Opalosolo