Question

Hello I have a Grails application which uses so far java.util.Date to store a timing value into a Microsoft SQL Server Database.

I load the date values form a .csv file with that format:

java.util.Date send_date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse(data[1]);

If I watch the var send_date with my debugger the field for milliseconds has the right value millis = 241

The variable send_date which is a java.util.Date type creates a Data Type = datetime column in my Database but then the value in the Database is 2007-10-04 10:10:53.240 This means the milliseconds are wrong. It always appears random, sometimes it is the right amount of milliseconds sometime +1 or -1.

Does anybody know a other data type which is compatible with my database, I already tried java.sql.Date but then I do not have a constructor to add this format "yyyy-MM-dd HH:mm:ss.SSS" If anybody knows how I can create another date object with this input format please let me know :)

Was it helpful?

Solution

SQL Server'd DATETIME data type has a 3 ms resolution. If you need a higher resolution use the DATETIME2 data type. It has a 100 ns resolution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top