Page 1 of 1

Formatting php S suffix for date

Posted: Wed Dec 10, 2008 3:57 am
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

Re: Formatting php S suffix for date

Posted: Wed Dec 10, 2008 3:59 am
by aceconcepts
take a look at http://uk2.php.net/date

Write it like:

Code: Select all

date("chosen_format", strtotime($_SESSION['booking']['from']));

Re: Formatting php S suffix for date

Posted: Wed Dec 10, 2008 4:45 am
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,

Re: Formatting php S suffix for date

Posted: Wed Dec 10, 2008 4:51 am
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']));