Solved

Strtotime returning -1

Posted on 2008-10-19
1
213 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

816 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now