Search code snippets, questions, articles... Chrome Extension

Convert Mysql date to Google sitemap date format PHP

Convert your MySql format date to the date that can be readable to Google sitemaps API using PHP
    $updated_date = '2021-01-28 11:52:19';

    $new_datetime = new DateTime($updated_date);
    $final_date = $new_datetime->format('Y-m-d\TH:i:sP');

    echo $final_date; //2021-01-28T11:52:19+01:00
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

In the code snippet, we have stored the date to our MySql database and when we try to create a sitemap, we need to change the format of the date so that the google sitemap API could red it unless it will throw the error. We are using the DateTime function of PHP for that and then its 'format' method to get the desired format date.

Search Index Data (The code snippet can also be found with below search text)

Google Sitemap date PHP Mysql
Was this helpful?
Join Devsheet Ask a Question