Chrome Extension

Convert String date to DATE MONTH-NAME YEAR format php

To convert a string to a formatted date you can use the date() method in PHP
    $date_str = "10-01-2021";
    $full_date= strtotime($date_str); 
    echo date('d F Y', $full_date); 
    //PRINT- 10 January 2021
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
10 January 2021

In the code snippet, we want to convert our date string '10-01-2021' to '10 January 2021'. To do this we use strtotime() method of PHP to convert the date string and then pass its value to the PHP date() function.

You can change 'd F Y' value according to your requirement. Like if you only want month name and year you can use

    echo date('F Y', $full_date);
    //PRINTS- January 2021
Was this helpful?
Join Devsheet Ask a Question