Jump to content


Photo

turn 2006-05-01 to 1st


  • Please log in to reply
3 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 18 September 2006 - 08:04 PM

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

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 18 September 2006 - 08:09 PM

very close... i'd recommend something like this:
<?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');
?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 18 September 2006 - 08:20 PM

please dont say look at the date() function because it doesnt explain it there...

Have you looked recently? Use the 'S'  format character:
<?php
echo date ('F jS',strtotime('2006-05-01'));
?>

Ken

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 19 September 2006 - 12:36 AM

please dont say look at the date() function because it doesnt explain it there...

Have you looked recently? Use the 'S'  format character:
<?php
echo date ('F jS',strtotime('2006-05-01'));
?>

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


You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users