[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-06-07
5
Medium Priority
?
1,287 Views
Last Modified: 2008-02-01
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  
0
Comment
Question by:coolgem
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Autogard
ID: 16856544
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
 
LVL 8

Expert Comment

by:Autogard
ID: 16856713
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
 
LVL 16

Accepted Solution

by:
suprapto45 earned 1000 total points
ID: 16858007
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
 

Author Comment

by:coolgem
ID: 16871121
What is sdf.parse(rs.getTimeStamp("yourDateColumn"));
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 16875428
Thanks for accepting.

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

David
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Loops Section Overview

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question