Akira Posted June 18, 2008 Share Posted June 18, 2008 Hey all, I just don't get it. I have dates stored in my DB in the following format; 16/06/2008 I want to convert them to; 16 June 2008. using following to do so; $date = strftime("%d %B %Y",strtotime("$row[enddate]")); Now, i just don't get it... cause the strotime function doens't make a timestamp. Output = empty. but when I use a normal string, like; $date = strftime("%d %B %Y",strtotime("16/06/2008")); No problems. What am i doing wrong here?? Tried every combination; strtotime("$row[enddate]") strtotime($row['enddate']) strtotime($row[enddate]) Running 2003 Server, IIS 6, PHP 5.2. Hope somebody has an anwser, out of ideas ^^ Quote Link to comment https://forums.phpfreaks.com/topic/110778-strtotime-problems/ Share on other sites More sharing options...
rarebit Posted June 18, 2008 Share Posted June 18, 2008 it should be: $date = strftime("%d %B %Y",strtotime($row['enddate'])); I suppose you also test print out $row['enddate']... to see what is in there is what you expect? Quote Link to comment https://forums.phpfreaks.com/topic/110778-strtotime-problems/#findComment-568329 Share on other sites More sharing options...
Akira Posted June 18, 2008 Author Share Posted June 18, 2008 Thanks for replying! $date = strftime("%d %B %Y",strtotime($row['enddate'])); Still no output. And yes, at first i used; print $row['enddate']; but to give it a better look, I wanted to convert the date. So i'm sure that the $row['enddate'] is filled Quote Link to comment https://forums.phpfreaks.com/topic/110778-strtotime-problems/#findComment-568335 Share on other sites More sharing options...
kenrbnsn Posted June 18, 2008 Share Posted June 18, 2008 The strtotime() function doesn't like dates in the format dd/mm/yyyy, so you need to convert that date into a format it likes: mm/dd/yyyy: <?php list($d,$m,$y) = explode('/',$row['enddate']); $date = strftime("%d %B %Y",strtotime("$m/$d/$y")); ?> It would be much better if you stored the date in your DB as YYYY-MM-DD, then you could take advantage of the many date features of mysql. Ken Quote Link to comment https://forums.phpfreaks.com/topic/110778-strtotime-problems/#findComment-568363 Share on other sites More sharing options...
Barand Posted June 18, 2008 Share Posted June 18, 2008 but when I use a normal string, like; $date = strftime("%d %B %Y",strtotime("16/06/2008")); No problems. When this code <?php $date = strftime("%d %B %Y",strtotime("16/06/2008")); echo $date; ?> outputs "01 January 1970 ", then I'd say you have problems Quote Link to comment https://forums.phpfreaks.com/topic/110778-strtotime-problems/#findComment-568414 Share on other sites More sharing options...
Akira Posted June 19, 2008 Author Share Posted June 19, 2008 When this code <?php $date = strftime("%d %B %Y",strtotime("16/06/2008")); echo $date; ?> outputs "01 January 1970 ", then I'd say you have problems hehe, nope, that code gives a nice output of 16 June 2008, like i said, no problems their Quote Link to comment https://forums.phpfreaks.com/topic/110778-strtotime-problems/#findComment-568873 Share on other sites More sharing options...
Akira Posted June 19, 2008 Author Share Posted June 19, 2008 The strtotime() function doesn't like dates in the format dd/mm/yyyy, so you need to convert that date into a format it likes: mm/dd/yyyy: <?php list($d,$m,$y) = explode('/',$row['enddate']); $date = strftime("%d %B %Y",strtotime("$m/$d/$y")); ?> It would be much better if you stored the date in your DB as YYYY-MM-DD, then you could take advantage of the many date features of mysql. Ken Hey Ken, Thanks heaps for this! Added your code, and it works now Weird that this isn't well documented at php.net. Quote Link to comment https://forums.phpfreaks.com/topic/110778-strtotime-problems/#findComment-568886 Share on other sites More sharing options...
PFMaBiSmAd Posted June 19, 2008 Share Posted June 19, 2008 On the strtotime() page in the php manual, there is a link to a "Date Input Formats" page. Under Calendar date items, it lists the date formats that are supported - http://www.gnu.org/software/tar/manual/html_node/Calendar-date-items.html#SEC116 Quote Link to comment https://forums.phpfreaks.com/topic/110778-strtotime-problems/#findComment-569037 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.