xshanelarsonx Posted February 22, 2007 Share Posted February 22, 2007 This will only show the day, and month. Why won't the year show? <?php $date = "22/2/2007"; $splitdate = explode("/", $date); $day = $splitdate[count(splitdate) -1]; $month = $splitdate[count(splitdate) -0]; $year = $splitdate[count(splitdate) -3]; echo "Date: $date<br> Day: $day<br> Month: $month<br> Year: $year"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/39711-solved-explode-problem/ Share on other sites More sharing options...
Yesideez Posted February 22, 2007 Share Posted February 22, 2007 The year is set to -3 try -2 instead. This code is a little tidier... <?php $date = "22/2/2007"; $splitdate = explode("/", $date); $day = $splitdate[0]; $month = $splitdate[1]; $year = $splitdate[2]; echo "Date: $date<br> Day: $day<br> Month: $month<br> Year: $year"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/39711-solved-explode-problem/#findComment-191710 Share on other sites More sharing options...
JBS103 Posted February 22, 2007 Share Posted February 22, 2007 It needs to be count($splitdate) for each one. count(splitdate) Returns 1, allowing for the day and month to work, but not year. There are more efficient ways of doing this. Quote Link to comment https://forums.phpfreaks.com/topic/39711-solved-explode-problem/#findComment-191714 Share on other sites More sharing options...
xshanelarsonx Posted February 22, 2007 Author Share Posted February 22, 2007 Thanks Yesideez! Its working now. Quote Link to comment https://forums.phpfreaks.com/topic/39711-solved-explode-problem/#findComment-191716 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.