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

Posted on 2006-06-07
Last Modified: 2008-02-01
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.
Question by:coolgem
    LVL 8

    Expert Comment

    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 ( or
    LVL 8

    Expert Comment


    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".
    LVL 16

    Accepted Solution


    If I were you, I would go for SimpleDateFormat.

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

    then later on



    Author Comment

    What is sdf.parse(rs.getTimeStamp("yourDateColumn"));
    LVL 16

    Expert Comment

    Thanks for accepting.

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    Title # Comments Views Activity
    static class 3 44
    My 2003 Land Rover discovery 2 key for code for car alarm 7 55
    Replace a tag with sed 2 30
    wordcount challenge 11 46
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    This is about my first experience with programming Arduino.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    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…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now