Jump to content

turn 2006-05-01 to 1st


brown2005

Recommended Posts

if i have

$a = $array['date'];

and $a is now 2006-05-01

how 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

very close... i'd recommend something like this:
[code]
<?php
function 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

[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]<?php
echo 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 :P

Ken
[/quote]
Link to comment
https://forums.phpfreaks.com/topic/21188-turn-2006-05-01-to-1st/#findComment-94330
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.