I have a Date/Time problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

I have a Date/Time problem

Post by myleow »

I will be receiving Date Time format that conform to ISO 8601 format.

Code: Select all

$date1 = '20040816T202020Z';
and

Code: Select all

$date2 = '2004-08-16T22:20:20+02:00';
I need to compare both $date1 and $date2, a simple > won't work because of the hyphens. Is there a way to do this with a premade function?

Another question is the +02:00 for $date2 is the time zone indication, is there a possibility that that doesn't exist?

Regards
Mian
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

I don't know of a function, but you could do:

Code: Select all

<?php
$chararray = array("-", ":");
$date3 = str_replace($chararray, "", substr($date2, 0, -6));

if ($date1 > $date3)
{
    //Carry on
?>
Post Reply