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
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; }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.