jarvis Posted July 29, 2010 Share Posted July 29, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/209223-convert-string-to-date-issue/ Share on other sites More sharing options...
tomtimms Posted July 29, 2010 Share Posted July 29, 2010 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; } Quote Link to comment https://forums.phpfreaks.com/topic/209223-convert-string-to-date-issue/#findComment-1092556 Share on other sites More sharing options...
jarvis Posted July 29, 2010 Author Share Posted July 29, 2010 thanks tomtimms that did the job nicely! Sometimes, things can be so simple, you just need the know how! Quote Link to comment https://forums.phpfreaks.com/topic/209223-convert-string-to-date-issue/#findComment-1092559 Share on other sites More sharing options...
tomtimms Posted July 29, 2010 Share Posted July 29, 2010 Check my changes to see check if the date is set. Quote Link to comment https://forums.phpfreaks.com/topic/209223-convert-string-to-date-issue/#findComment-1092560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.