Jump to content

convert string to date issue


jarvis

Recommended Posts

Hi,

 

Sorry, me again!

 

Ok, so i've got my url:

http://www.mydomain.com/?ec3_after=2010-08-01&ec3_before=2010-08-07

 

I've then got the following code to get the values:

$afterDateParts = split("-", $_GET['ec3_after']); 
$after = $afterDateParts[2] . " " . $afterDateParts[1] . " " . $afterDateParts[0]; 
echo $after; 

which returns:

01 08 2010 (correct for this demo)

 

I've then got this to convert the above into a nicer format:

$convertMe = strtotime($after);
echo date('d-M-Y', $convertMe);

But it always returns:

01 Jan 1970

 

For the love of god, I cannot work out why. Is it really not that simple?  :'(

 

Please someone put me out my misery. I'm loosing hair by the minute! Lol

 

TIA

Link to comment
https://forums.phpfreaks.com/topic/209223-convert-string-to-date-issue/
Share on other sites

You got me confused on what your doing, if your just trying to get the variable from the url why not just do this?

 

$test = $_GET['ec3_after'];
$test_date = date("d-M-Y",strtotime($test));
echo $test_date;  //// displays 01-Aug-2010 

 

or if you want to make sure the date is set you would do

 

if(isset($_GET['ec3_after'])) { $test = $_GET['ec3_after']; $test_date = date("d-M-Y",strtotime($test)); echo $test_date; }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.