Hi
What is the problem with the mysql syntax
SELECT FORMAT(dCreatedDate,'YYYY-MM-DD') as date1 FROM tbl_book_self
I want to select the date from mysql database in this format,How to use this syntax
views:
11answers:
3
+1
A:
Did you mean to use DATE_FORMAT
rather than just FORMAT
?
Also the format needs to be specified using %
notation so the corrected version of your example would be
DATE_FORMAT(dCreatedDate, '%Y-%m-%d')
You can find a list of the specifiers you can use in the format string in the MySQL documentation on Date and Time Functions.
mikej
2010-07-14 12:08:08
@mikej:http://w3schools.com/sql/sql_func_format.aspPlease have an look at this link
udaya
2010-07-14 12:11:23
@mikej: The query actually resulted in fetching date in correct format these days i did the same work by exploding the datas in the view page and by displaying in some format
udaya
2010-07-14 12:13:04
The w3school tutorial is a general SQL tutorial and is not specific to MySQL. In MySQL the function for formatting dates is `DATE_FORMAT`. MySQL does have a function called `FORMAT` but that is for [formatting numbers to a format like '#,###,###.##'](http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_format).
mikej
2010-07-14 12:19:50
@mikej : i can can understand what you mean
udaya
2010-07-14 12:22:24
From your second comment where you say it *actually resulted in fetching date in correct format these days* do you mean that you have fixed your problem now? If not, I think you might need to edit your question to clarify what it is you're asking. Attempting to use `FORMAT` with a 2nd parameter of `YYYY-MM-DD` will definitely result in `You have an error in your SQL syntax`.
mikej
2010-07-14 12:24:26
@mike j : actually it results weong i tried what you said.....You are correct SELECT DATE_FORMAT(dCreatedDate, '%d-%M-%Y') as perdate FROM tbl_book_selfThis works perfect for me
udaya
2010-07-14 12:28:55
@mikej : thanks
udaya
2010-07-14 12:29:12
A:
mysql> SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
-> 'Sunday October 2009'
mysql> SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
-> '22:23:00'
mysql> SELECT DATE_FORMAT('1900-10-04 22:23:00',
-> '%D %y %a %d %m %b %j');
-> '4th 00 Thu 04 10 Oct 277'
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00',
-> '%H %k %I %r %T %S %w');
-> '22 22 10 10:23:00 PM 22:23:00 00 6'
mysql> SELECT DATE_FORMAT('1999-01-01', '%X %V');
-> '1998 52'
mysql> SELECT DATE_FORMAT('2006-06-00', '%d');
-> '00'
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date
Judas Imam
2010-07-14 12:10:06
A:
SELECT DATE_FORMAT(dCreatedDate,'%Y-%m-%d') as date1 FROM tbl_book_self
ritesh choudhary
2010-07-14 12:13:33