How do you validate ISO 8601 date string (ex: 2011-10-02T23:25:42Z).
I know that there are several possible representations of ISO 8601 dates, but I\'m only interest
Edit: By far the easiest method is to simply try to create a DateTime object using the string, eg
$dt = new DateTime($dateTimeString);
If the DateTime constructor cannot parse the string, it will throw an exception, eg
DateTime::__construct(): Failed to parse time string (2011-10-02T23:25:72Z) at position 18 (2): Unexpected character
Note that if you leave off the time zone designator, it will use the configured default timezone.
Second easiest method is to use a regular expression. Something like this aught to cover it
if (preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|(\+|-)\d{2}(:?\d{2})?)$/', $dateString, $parts)) {
// valid string format, can now check parts
$year = $parts[1];
$month = $parts[2];
$day = $parts[3];
// etc
}