In sql datbase when date datatype is used it stores date in yyyy-mm-dd format is there any way to change it to dd-mm-yyyy? as i want to display date in dd-mm-yyyy format. One way or another would be helpful.
4 Answers
You can use MySQL's built in DATE_FORMAT function in the query:
SELECT DATE_FORMAT(datefield, '%d-%m-%Y'); OR
SELECT DATE_FORMAT(datefield, GET_FORMAT(DATE,'EUR')); If you use GET_FORMAT(DATE,'EUR') it will use . instead of - as the separator though.
1 Comment
You Old Fool
This is probably the best solution... though to say for sure would depend on workflow and preference.
I prefer to save your date in UNIX format so you can use
date("<IDENTIFER>", $timestampUNIX); to make a timestamp in any format you want. For identifers use http://php.net/manual/en/function.date.php
For this you have to change your database-colum-type to INT.
1 Comment
You Old Fool
Though this is perfectly acceptable it does make it hard for a human to make heads or tails of the data without converting it.