Michan Posted November 10, 2006 Share Posted November 10, 2006 Hi there,I have two date formats; I was wondering how I could convert both of these into a readable format, like "10th Nov 2006", using some PHP.2006-11-10 13:26:271163197621I have hunted around, but I just can't seem to rasp how these dates would be converted. And I don't have a single clue on the second one X_X;Many thanks in advance,- Mi Link to comment https://forums.phpfreaks.com/topic/26875-converting-date-into-readable-format/ Share on other sites More sharing options...
Psycho Posted November 11, 2006 Share Posted November 11, 2006 Take a look at the manual for the date() function. It's not all that hard. You use it as follows:date ( [i]parameters[/i], [i]timestamp[/i]);The timestamp is an integer representation of the time that you want displayed The parameters are the options of how you want the data or time displayed.For what you want you would use date( 'dS F Y' , [i]timestamp[/i]);The d is for the day of the monthThe S is for the ordinal suffix for the day of the month (1st, 2nd, 3rd, 4th, etc.)The M is for the 3 character representation of the monthThe Y is for the 4 digit year.You can also add additional text such as date( 'dS \of F Y' , [i]timestamp[/i]);would represent "1st of Jan 2006"The 2nd date format you have is a timestamp and you can use it as it. The 1st one would need to be converted to a timestamp first.You could so it like this:$date = "2006-11-10 13:26:27";$month = substr($date, 5, 2);$day = substr($date, 8, 2);$year = substr($date, 0, 4);$timestamp = mktime (0, 0, 0, $month, $day, $year);$newdate = date( 'dS F Y' , $timestamp);; Link to comment https://forums.phpfreaks.com/topic/26875-converting-date-into-readable-format/#findComment-122928 Share on other sites More sharing options...
Michan Posted November 11, 2006 Author Share Posted November 11, 2006 Thank you for explaining it, that works perfectly :) Link to comment https://forums.phpfreaks.com/topic/26875-converting-date-into-readable-format/#findComment-122991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.