Home     Articles & Projects     Products & Web Services     Forum

Change date(y-m-d,$date) in MySQL

I am wondering if anyone knows, is there anyway to change the date formate on a timestamp, before you print the timestamp I was thinking something like this.

SELECT date(y-m-d,date) FROM date

Hi Russell, If the date is

Hi Russell,

If the date is being stored in native MySQL date format use strtotime() against the SELECT'ed value and then format the result of that required, for example;

$date = date("y-m-d",strtotime($row["date"]));

(where "y-m-d" is the format you require according to the date() function documentation)

Cheers,
David.

Sadly that wont work for

Sadly that wont work for what I need to do. Cos i need to group the date rows together by day, so I need it to forget that the date row also has the time in the string.

Hi Russell, Have a look

Hi Russell,

Have a look at...

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

...for example to GROUP only by the date component of a date/time value; you could use:

SELECT *,DATE(date) AS day FROM table WHERE whatever GROUP BY day;

Hope this helps!
Cheers,
David.

Thanks David, I needed to

Thanks David,
I needed to use

SELECT DATE_FORMAT('2009-10-04 22:23:00', '%d/%c/%Y');

The code above shows 04/10/2009

Now that's Cool