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"; ?> 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"; ?> 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. 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. Link to comment https://forums.phpfreaks.com/topic/39711-solved-explode-problem/#findComment-191716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.