Jump to content

Archived

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

brown2005

turn 2006-05-01 to 1st

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.....

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
[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]

Ken

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.