2

I am using the following statements to change the pattern of date to be stored in "MM/dd/yyyy" format. In my SQL database, Date field is in "DATE" type format. But, I can't understand why in my database still it shows the value as "2014-02-21". It seems very weird to me, because I have defined a pattern for date.

I appreciate any help, I spent a day on it...still stuck and can't proceed:(

        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        Calendar cal = Calendar.getInstance();
        String s=dateFormat.format(cal.getTime());
        java.util.Date myDate=new java.util.Date(s);
        java.sql.Date sqlDate=new java.sql.Date(myDate.getTime());
        timeVO.set_Date(sqlDate); (store sqlDate in timeVO object- sqlDate is Date      type defined in object)
2
  • 1
    It doesn't make sense to me to convert a Date value to string to submit to database ... have you tried timeVO.set_Date(cal.getTime()); or is it not possible because of the method signature? Commented Feb 21, 2014 at 11:11
  • (Wikipedia page for ISO 8601) expressed according to ISO 8601: Date: 2014-02-17 Commented Feb 21, 2014 at 18:17

1 Answer 1

2

I don't know exactly how sql server handles dates, but I suppose that the format is not stored in database, dbms stores date objects as a number (e.g. number of seconds since 01.01.1970), so does JVM, and date format is just a representation for printing it on screen - the thing you see in your database is only a printable form shown by your database client, and not how actually it is stored behind the scenes

Sign up to request clarification or add additional context in comments.

1 Comment

+1 - Yes, most modern RDBMSs do essentially what the JVM does, and store an offset since a given epoch (this makes sorting/searching really efficient/simple). This is exactly what his problem is; resolution depends on what he's actually looking for... probably, he needs to update the display format used in his client. The DATE type itself can't be changed. Attempting to store the value in the given format in a character-based type will result in a lot of trouble later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.