Java: Insure a date is in DD MMM YYYY format.

Hi,
I'm trying to convert a date obtain via sql. Take the date and in a setter conver the date such that it looks like DD MMM YYYY.
Thanku4urtime  
coolgemAsked:
Who is Participating?
 
suprapto45Connect With a Mentor Commented:
Well,

If I were you, I would go for SimpleDateFormat.

SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");

then later on

sdf.parse(rs.getTimeStamp("yourDateColumn"));

David
0
 
AutogardCommented:
Can you just format the date in the format that you want it directly in your SQL query?  Something like "DATE_FORMAT(dateyouwanttoconvert, '%d %b %Y')".  This is if you have it stored as a DATE/DATETIME datatype in sql.

If you would rather do it in your programming logic most languages will have a way to format dates how you would like them.  Java's SimpleDateFormat or DateFormat should work (http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html or http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html).
0
 
AutogardCommented:
Example:

Say you have a table called "mydates" and at mydate_id =2 you have a column called mydate_date with the date value (2006-06-07 15:20:05) you want formatted...

"SELECT DATE_FORMAT(mydate_date, '%d %b %Y') as formatted_date FROM mydates WHERE mydate_id = 2"

With this query "formatted_date" now contains "07 Jun 2006".
0
 
coolgemAuthor Commented:
What is sdf.parse(rs.getTimeStamp("yourDateColumn"));
0
 
suprapto45Commented:
Thanks for accepting.

It is used to *parse* your date in this case (rs.getTimeStamp("yourDateColumn")) to be a String.

David
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.