James986 Posted November 27, 2006 Share Posted November 27, 2006 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/2006But I want to format it so it appears similar to this:Wednesday, 22 November 2006Can this be done?Thanks In Advance,James Link to comment https://forums.phpfreaks.com/topic/28634-string-formattingdate-formatting/ Share on other sites More sharing options...
kenrbnsn Posted November 27, 2006 Share Posted November 27, 2006 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 Link to comment https://forums.phpfreaks.com/topic/28634-string-formattingdate-formatting/#findComment-131028 Share on other sites More sharing options...
James986 Posted November 30, 2006 Author Share Posted November 30, 2006 Thanks for that! it worked :)I changed the database like you suggested. Link to comment https://forums.phpfreaks.com/topic/28634-string-formattingdate-formatting/#findComment-132756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.