• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Strtotime returning -1

Can you tell me why strtotime is returning -1 for the value '2008-10-15T18:20:24-07:00'. Trying to get a unix time stamp for that string.

0
qwertq
Asked:
qwertq
1 Solution
 
Scripting_GuyCommented:
-1 means that it failed to parse the string (prior to php 5.something, they changed that so the function returns false in more recent versions).

This also means, that strtotime won't help you here. this might:

[code]
<?php

$string = '2008-10-15T18:20:24-07:00';
preg_match ('/([\d]+)-([\d]+)-([\d]+)T([\d]+):([\d]+):([\d]+).*/s', $string, $hits);
$timestamp = mktime ($hits[4], $hits[5], $hits[6], $hits[2], $hits[3], $hits[1]);
echo $timestamp;
?>
[/code]
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now