PDA

View Full Version : PHP Date Format


centenial
12-12-2006, 08:04 PM
Hi,

I have a database table with several hundred records. The DB table has these fields:
- id
- name
- date

All the dates are in YYYY-MM-DD format. However, when they're displayed on my website, I want the dates to display like this:

Jan 1, 2006 or
Dec 12, 2006 (whatever the correct date is)

Is there a function in PHP that I can use to convert YYYY-MM-DD to the more elegant format above?

Thanks for your help,

Tyree
12-12-2006, 08:13 PM
Use strtotime() in conjunction with date() to get the look you want.

For example:

$dbDate = strtotime(date from your db);
$newDate = date("M j, Y", $dbDate);


strtotime() converts any date string to a timestamp and then date() can take any time stamp and format it as a date.

Check out php.net for more.

guelphdad
12-12-2006, 08:35 PM
if you are using mysql then you can use DATE_FORMAT directly in your sql select query to do so.