Jump to content

String Formatting/Date Formatting


James986

Recommended Posts

Hello,

I am extremely new to php so any help you can provide is extremely useful for me.


I have a string which has been taken from a database. This string is a date. E.g: 22/11/2006

But I want to format it so it appears similar to this:
Wednesday, 22 November 2006

Can this be done?


Thanks In Advance,
James
Link to comment
https://forums.phpfreaks.com/topic/28634-string-formattingdate-formatting/
Share on other sites

I would suggest using a combination of the [url=http://www.php.net/strtotime]strtotime()[/url] and [url=http://www.php.net/date]date()[/url] functions. Since you are not using the American date format of 'mm/dd/yyyy', which is the format the strtotime() function recognizes, you need to do a little more work.

[code]<?php
$date_str = '22/11/2006';
list ($day, $month, $year) = explode('/',$date_str);
echo date('l, j F Y',strtotime($month . '/' . $day . '/' . $year));
?>[/code]

To make your life easier, you may want to consider storing the date in the database in the format 'yyyy-mm-dd', which can be displayed any way you want.

Ken

Archived

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

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