how to convert JAVA string in "hh:mm dd/mm/yyyy" to sql datetime format? - JDBC JAVA

This is a discussion on how to convert JAVA string in "hh:mm dd/mm/yyyy" to sql datetime format? - JDBC JAVA ; Hi, In my JAVA code I have a string in "15:45 03/17/2007" this format. Could any one let me know how can i insert/update it on to sql database where the column is of type datetime ? If any one ...

+ Reply to Thread
Results 1 to 7 of 7

how to convert JAVA string in "hh:mm dd/mm/yyyy" to sql datetime format?

  1. Default how to convert JAVA string in "hh:mm dd/mm/yyyy" to sql datetime format?

    Hi,
    In my JAVA code I have a string in "15:45 03/17/2007" this format.
    Could any one let me know how can i insert/update it on to sql
    database where the column is of type datetime ? If any one has a
    sample code to do this, that will be great.
    Regards,
    Shivaraj


  2. Default Re: how to convert JAVA string in "hh:mm dd/mm/yyyy" to sql datetimeformat?

    shivaraj wrote:
    > Hi,
    > In my JAVA code I have a string in "15:45 03/17/2007" this format.
    > Could any one let me know how can i insert/update it on to sql
    > database where the column is of type datetime ? If any one has a
    > sample code to do this, that will be great.


    Your subject line says "hh:mm dd/mm/yyyy" but the example you quote is
    not a valid date in that format, there is no month 17.

    I'd use String split to decompose the date and time and the use String
    concatenation to reassemble the parts in the form expected by SQL.

  3. Default Re: how to convert JAVA string in "hh:mm dd/mm/yyyy" to sql datetimeformat?

    shivaraj wrote:
    > In my JAVA code I have a string in "15:45 03/17/2007" this format.
    > Could any one let me know how can i insert/update it on to sql
    > database where the column is of type datetime ? If any one has a
    > sample code to do this, that will be great.


    Use SimpleDateFormat parse to convert your string to a
    java.util.Date and use a PreparedStatement for using
    it in SQL (you need to wrap it in a java.sql.TimeStamp, but that
    is trivial).

    Arne

  4. Default Re: how to convert JAVA string in "hh:mm dd/mm/yyyy" to sql datetime format?

    On Mar 19, 4:53 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
    > shivaraj wrote:
    > > In my JAVA code I have a string in "15:45 03/17/2007" this format.
    > > Could any one let me know how can i insert/update it on to sql
    > > database where the column is of type datetime ? If any one has a
    > > sample code to do this, that will be great.

    >
    > Use SimpleDateFormat parse to convert your string to a
    > java.util.Date and use a PreparedStatement for using
    > it in SQL (you need to wrap it in a java.sql.TimeStamp, but that
    > is trivial).
    >
    > Arne


    Hi Ian/Arne,

    Thanks for your comments.
    Ian,
    by mistakly I said it as ""hh:mm dd/mm/yyyy" but it is ""hh:mm
    mm/dd/yyyy" format. I will try splitting that string into date and
    time and try to use it as sql date format.
    Arne,
    To try with this approach, I am not getting any patterns in
    "hh:mm mm/dd/yyyy" in SimpleDateFormat to convert it into java date
    format. If that is the case again I have to split it as Ian said. Is
    that so or am i missing something?

    Regards,
    Shivaraj


  5. Default Re: how to convert JAVA string in "hh:mm dd/mm/yyyy" to sql datetime format?

    "shivaraj" <shivaraj.malannavar> writes:

    > To try with this approach, I am not getting any patterns in
    > "hh:mm mm/dd/yyyy" in SimpleDateFormat to convert it into java date
    > format. If that is the case again I have to split it as Ian said. Is
    > that so or am i missing something?


    Read the API documentation about it. We humans understand the two
    different ways you use "mm", but SimpleDateFormat has its own way of
    differentiating minutes and months.

    --

    http://ourdoings.com/
    Amazingly simple photo sharing

  6. Default Re: how to convert JAVA string in "hh:mm dd/mm/yyyy" to sql datetimeformat?

    shivaraj wrote:
    > On Mar 19, 4:53 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:

    [SNIP]
    > Ian,
    > by mistakly I said it as ""hh:mm dd/mm/yyyy" but it is ""hh:mm
    > mm/dd/yyyy" format. I will try splitting that string into date and
    > time and try to use it as sql date format.
    > Arne,
    > To try with this approach, I am not getting any patterns in
    > "hh:mm mm/dd/yyyy" in SimpleDateFormat to convert it into java date
    > format. If that is the case again I have to split it as Ian said. Is
    > that so or am i missing something?


    You should read the Javadoc for java.text.SimpleDateFormat more carefully.

    Lowercase 'm' denotes minutes in an hour, whereas uppercase 'M' denotes
    months in a year. You cannot assume that you can use 'm' for both month
    and minute.

    You also need to beware of the distinction between 'h' and 'H' for the
    hour. Both are valid, but they will yield different results.

    Attention to detail is vital.

    David Harper
    Cambridge, England

  7. Default Re: how to convert JAVA string in "hh:mm dd/mm/yyyy" to sql datetime format?

    Bruce Lewis wrote:
    > Read the API documentation about it. We humans understand the two
    > different ways you use "mm", but SimpleDateFormat has its own way of
    > differentiating minutes and months.


    Absolutely. Just use "mm" for minutes and "MM" for months.

    Bye, Emanuele
    --
    Linux engine 2.6.17-11-generic i686 GNU/Linux

+ Reply to Thread

Similar Threads

  1. convert MM/dd/yyyy format into dd/MM/yyyy
    By Application Development in forum DOTNET
    Replies: 4
    Last Post: 08-30-2007, 05:18 AM
  2. Change column of DateTime type to "long date" format
    By Application Development in forum DOTNET
    Replies: 4
    Last Post: 05-27-2007, 09:19 AM
  3. Display DateTime column in "long date" format
    By Application Development in forum DOTNET
    Replies: 0
    Last Post: 05-25-2007, 12:34 PM
  4. Convert string to DateTime Format
    By Application Development in forum CSharp
    Replies: 1
    Last Post: 08-30-2005, 05:41 AM
  5. convert a custom format string back to datetime
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 09-25-2004, 12:48 AM