• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

mySQL function date_format() not working in java application

 
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?

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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.
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic