• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mySQL function date_format() not working in java application

 
fady zohdy
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to get the manufacturing date and expiry date in the dd-mm-yyyy format using the date_format() function in mySQL but it keeps giving me this format sat mar 28 00:00:00 EET 2015.
the manufacturing_date and expiry_date columns in the mysql table are set to date value.
i used the str_to_date(d,'%d-%m-%Y') function when inserting the value into the table.
and i tried the date_format() function in the command prompt and it gave me the desired output!!!
can anybody help me please?

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15644
48
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you seeing the wrong format? How are you getting the data from the result set?

Note that Date objects do not have a format by themselves. If you are getting the results as Date objects, then they will just contain the date value - without any format.

If you want to display a Date in a particular format, you'll have to format it at the point where you're going to display it, for example using a SimpleDateFormat. Example:
 
fady zohdy
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:
Note that Date objects do not have a format by themselves. If you are getting the results as Date objects, then they will just contain the date value - without any format.
[/code]

it worked. thanks.
i did use the Date class but i thought the date_format() function will format the date before passing it to the Date object. it seems i miss understood.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic