View Full Version : Simple Date Question (Changing Formats)

11-11-2007, 06:21 PM
Hey everyone.

In my MySQL table I have a date-type column where I think I am storing dates incorrectly. I save them as something like 1986-03-26

I read up a bit and it seems this type is meant to have a timestamp... no?

Anyways, I can echo the date out as "1989-03-26" perfectly fine, but I want to say :

echo date("d F Y",$date);

This gives me 31 December 1986... not cool.

Anyone know of a solution?

Thanks a lot!

11-11-2007, 06:50 PM
MySQL's date field type uses the format YYYY-MM-DD. I don't know who told you it should be a timestamp, but they're mistaken. You can generate a timestamp when you select the date if that's what you want:

SELECT UNIX_TIMESTAMP(`datecolumn`) AS `timestamp` FROM `table` WHERE 1

11-11-2007, 08:27 PM
The 2nd argument in the date function accepts a timestamp. You can either do as Inigoesdr suggested above and have the database return you a timestamp or do this instead with your regular date

echo date("d F Y",strtotime($date));

11-12-2007, 03:59 PM
echo date("d F Y",strtotime($date));

This is just plain silly, it's wasting server resources.

MySQL allows you to format the date in the query.

Look up DATE_FORMAT() (for MySQL).