Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am having a column date in Mysql table.
date displays like 2014-01-09
Now i need to convert this format to 09-01-2014 and to display in my php file
i used a function in a query like
select str_to_date('date','%d-%m-%Y') from `table_name`;
but i cant get correct
is there any mistake in the above query function format?




Thanks
Posted
Updated 9-Jan-14 1:06am
v2

Date time formate[^]


Date Time Formate[^]




PHP
$date = new DateTime('2014-01-09');
echo $date->format('d-m-Y');
 
Share this answer
 
v2
There is a full example to be found at http://www.w3resource.com/mysql/date-and-time-functions/mysql-str_to_date-function.php[^]. If that does not work for you then you need to give more details of what results you are seeing.
 
Share this answer
 
u can access each an every digit of your date in an array.
so change the sequence of array index to get the desired output
ex:
date=d[0].d[1].'-'.d[2].d[3].'-'.d[4].d[5].d[6].d[7];(date format DD-MM-YYYY)

similaryly
date=d[4].d[5].d[6].d[7].'-'.d[2].d[3].'-'.d[0].d[1];(date format YYYY-MM-DD)
 
Share this answer
 
select date_format(`date`,'%d-%m-%Y')
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900