Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mada72's avatar

compare current date with lastmod from sitemap,xml using php

Hi,

how can i compare (difference) between current date and lastmod from sitemap.xml?

0 likes
2 replies
Cronix's avatar
Cronix
Best Answer
Level 67

So you have a lastmod date like 2011-06-27T19:34:00+01:00.

$lastmod = Carbon\Carbon::parse('2011-06-27T19:34:00+01:00');

Then you can use any carbon commands to compare against now() (which is Laravels equivalent/shortcut to Carbon\Carbon::now()). You didn't say what you wanted to compare about it, but check the carbon docs. There are many ways (less than, greater than, elapsed days, elapsed seconds, etc.)

if ($lastmod->lt(now()) {} // is $lastmod less than right now

if (now()->diffInHours($lastmod) > 10) {} // is $lastmod older than 10 hours

etc.

https://carbon.nesbot.com/docs/#api-comparison

https://carbon.nesbot.com/docs/#api-difference

Please or to participate in this conversation.