1

I'm working with a web service that is doing an HTTP GET request to my server and sending the timestamp value as follows:

timeStamp=Mon+Jul+13+10%3A52%3A00+EST+2015

I then need to covert this into a timestamp I can insert into my database, but I'm having trouble extracting a valid value. I've tried using strtotime, e.g.:

echo(strtotime('Mon+Jul+13+10%3A52%3A00+EST+2015') );

but that doesn't return anything. The timestamp in this example is July 13th, 2015 at 10:52:00.

Looking for a solution to converting this string into a valid timestamp.

2
  • 5
    start with urldecode() Commented Jul 13, 2015 at 1:15
  • That's a rather odd time format. Commented Jul 13, 2015 at 1:29

2 Answers 2

2

This should work for you. You have received a urlencoded string, so you need to reverse this first.

FIDDLE

<?php
$timeStamp="Mon+Jul+13+10%3A52%3A00+EST+2015";
$timeStamp=urldecode($timeStamp); 
echo strtotime($timeStamp);
?>
Sign up to request clarification or add additional context in comments.

Comments

0

You just need to replace the "+" and "%3A" with a " " (space) and ":"

$good = array(' ', ':');
$bad = array ('+', '%3A');

echo str_replace($bad, $good, 'Mon+Jul+13+10%3A52%3A00+EST+2015');

Or if you want the numerical time, change the last line to this:

echo strtotime(str_replace($bad, $good, 'Mon+Jul+13+10%3A52%3A00+EST+2015'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.