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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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