Solved

Strtotime returning -1

Posted on 2008-10-19
1
220 Views
Last Modified: 2008-10-23
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
Comment
Question by:qwertq
1 Comment
 
LVL 3

Accepted Solution

by:
Scripting_Guy earned 125 total points
ID: 22754126
-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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question