I need date format for sitemaps in php.
How can i do that ?
Is this output right ?
<lastmod>2012-08-02EEST18:01:18+03:00</lastmod>
I need date format for sitemaps in php.
How can i do that ?
Is this output right ?
<lastmod>2012-08-02EEST18:01:18+03:00</lastmod>
delete "EES" Mine is like this 2013-12-26T19:00:00-05:00 and it works http://www.industry-automation-parts.com/1_e_0_sitemap.xml
If you have the timestamp you can format the date correctly like this:
Time stamp could be
time()
(for current time) or some other method of fetching a unix tiemstamp likestrtotime()
Actually, there are 2 approaches to this.
The first approach is to set a valid date for XML sitemap which includes the "C" char which gave the value: (2019-06-03T17:30:21-05:00). Test it here
<lastmod>'.date('c', strtotime($row['date'])).'</lastmod>
The 2nd approach is to set a valid date for RSS sitemap which includes the "r" char which gave the value: (2019-03-07T17:55:44+00:00).
<pubDate>'.date('r', strtotime($row['date'])).'</pubDate>
Hope this helps you. Thanks
To convert from a MySQL's datetime format to the one needed for lastmod in sitemaps, just use the PHP code below.
with moment.js;
Your getting this output because you used the old recommended timestamp string of
However, what you need is
This single back slash will make the difference. At some point a capital T became a special character in PHP signifying timecode, so if you don't escape the T you will get exactly what your reporting.