Formatting php S suffix for date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tta013
Forum Newbie
Posts: 3
Joined: Wed Aug 20, 2008 3:28 am

Formatting php S suffix for date

Post by tta013 »

Hi all,

I have got a date session vailable on my page and I write out the date in the following way :

<?php echo format_date($_SESSION['booking']['from']); ?> and it returns Wed 17 December 2008.

I was wondering if there is a way to format it so that it would come out like Wed 17th December 2008 ?

Many thanks
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Formatting php S suffix for date

Post by aceconcepts »

take a look at http://uk2.php.net/date

Write it like:

Code: Select all

date("chosen_format", strtotime($_SESSION['booking']['from']));
tta013
Forum Newbie
Posts: 3
Joined: Wed Aug 20, 2008 3:28 am

Re: Formatting php S suffix for date

Post by tta013 »

Hi Many thanks for your reply.

When I changed the code to<?php echo date("S", strtotime($_SESSION['booking']['from'])); ?> , it only came out as th. I am not sure where it when wrong...

Regards,
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Formatting php S suffix for date

Post by aceconcepts »

You have to declare the full format. "S" will only output "th" or "rd" etc...

Use the link i sent you to find out different formats to use e.g. If i wanted to format a date as "DD-MM-YYYY" i would write it like this:

Code: Select all

echo date("d-m-Y", strtotime($_SESSION['booking']['from']));
Post Reply