date format in JSP


Web tier: servlets, JSP, Web frameworks: date format in JSP

  1. date format in JSP (2 messages)


    my jsp contains three combos for 'day', 'month' ,'year'.

    the parameters are extracted and parsed to int type variable.
    I am using the (java.text.DateFormat) class to format the dates, so that I can store tham as
    (medium/long) data type in MSAccess database.

    I then passed the parameters to the dateconstructor.
    Date date_from= new Date(int year,int month,int day)

    then by using the simpledateformat class I tried to format the date as per the database acceptable date type(dd MMM yyyy).

    SimpleDateFormat sdf=new SimpleDateFormat(dd MMM yyyy);
    sdf.format( date_from);
    THE PROBLEM IS format() method returns as string, which cannot be stored as date datatype in any database. when I fire a query to the MSAccess database.
    exception is thrown " microsoftdatbase error datatype mismatch".

    I tried with MySQL database.
    Please , guys help me as only this problem is stoppingme in submitting my module for display , that is scheduled tomorrow. PLEASE HELP THIS IS URGENT"


    Threaded Messages (2)

  2. date format in JSP[ Go to top ]

    Vijay, you may try a couple of things. When updating Access date fields, I've found the following format to work:

    #MM/dd/yyyy#, for instance: update ... set dt="#04/01/2001"

    You'll need the pound(#) signs.

    For other datebase types, you can try:

    'yyyy-MM-dd', for instance: update ... set dt="'2001-04-01'"

    Finally, jdbc supports an escape sequence that is supposed to translate a date to the format required by the underlying database for you. I've never tried it, but if you want to experiment, that format is:

    {d 'yyyy-mm-dd'}, for instance: update ... set dt={d '2001-04-01'}

    You need the curly braces. You may need to enclose the entire expression in quotes, "...", I'm not sure.

  3. date format in JSP[ Go to top ]

    Here is an example code:
    java.util.Date dt = new java.util.Date();
    Calendar c = Calendar.getInstance();
    TimeZone tz = c.getTimeZone();
    SimpleDateFormat dfm = new SimpleDateFormat("yyyyMMddHHmmss");
    String currentDay = dfm.format(dt);
    currentDay contains Todays date in yyyyMMddHHmmss format.