Jump to content

Converting date into readable format


Michan

Recommended Posts

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:27

1163197621

I 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

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 month
The 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 month
The 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);;

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.