brown2005 Posted September 18, 2006 Share Posted September 18, 2006 if i have$a = $array['date'];and $a is now 2006-05-01how do i turn that into the 1st.please dont say look at the date() function because it doesnt explain it there...thanks very much...p.s. i now its something like date('d', $a); or something like that... but dont u need to string it or somethin..... Link to comment https://forums.phpfreaks.com/topic/21188-turn-2006-05-01-to-1st/ Share on other sites More sharing options...
obsidian Posted September 18, 2006 Share Posted September 18, 2006 very close... i'd recommend something like this:[code]<?phpfunction dateSuffix($date) { $day = substr(date('d', strtotime($date)), -1); switch ($day) { case 1: $day .= 'st'; break; case 2: $day .= 'nd'; break; case 3: $day .= 'rd'; break; default: $day .= 'th'; } return $day;}echo dateSuffix('2006-05-01');?>[/code]hope this helps Link to comment https://forums.phpfreaks.com/topic/21188-turn-2006-05-01-to-1st/#findComment-94196 Share on other sites More sharing options...
kenrbnsn Posted September 18, 2006 Share Posted September 18, 2006 [quote]please dont say look at the date() function because it doesnt explain it there...[/quote]Have you looked recently? Use the 'S' format character:[code]<?phpecho date ('F jS',strtotime('2006-05-01'));?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/21188-turn-2006-05-01-to-1st/#findComment-94201 Share on other sites More sharing options...
obsidian Posted September 19, 2006 Share Posted September 19, 2006 [quote author=kenrbnsn link=topic=108537.msg436767#msg436767 date=1158610822][quote]please dont say look at the date() function because it doesnt explain it there...[/quote]Have you looked recently? Use the 'S' format character:[code]<?phpecho date ('F jS',strtotime('2006-05-01'));?>[/code]lol... no freaking way! i have used that 'S' modifier in many scripts, and i completely forgot about it when answering that post... thanks ken :PKen[/quote] Link to comment https://forums.phpfreaks.com/topic/21188-turn-2006-05-01-to-1st/#findComment-94330 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.