refiking Posted September 18, 2008 Share Posted September 18, 2008 I receive the date using a $date variable. And it comes in this format: 20081810 or Ymd How can I seperate this into $month = 10 $year = 2008 $day = 18 Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/124771-solved-format-a-date/ Share on other sites More sharing options...
ratcateme Posted September 18, 2008 Share Posted September 18, 2008 substr is good for this like $year = substr($date,0,4); $month = substr($date,4,2); $day = substr($date,6,2); but that requires the month and day to have leading zeros Scott. Quote Link to comment https://forums.phpfreaks.com/topic/124771-solved-format-a-date/#findComment-644533 Share on other sites More sharing options...
EKINdesigns Posted September 18, 2008 Share Posted September 18, 2008 $year = substr(0,4,$date); $day = substr(4,2,$date); $month= substr(6,2,$date); I think that should work. Quote Link to comment https://forums.phpfreaks.com/topic/124771-solved-format-a-date/#findComment-644534 Share on other sites More sharing options...
EKINdesigns Posted September 18, 2008 Share Posted September 18, 2008 Strike mine...The haystack is supposed to be the first var of the function. Quote Link to comment https://forums.phpfreaks.com/topic/124771-solved-format-a-date/#findComment-644536 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.