Storing dateCreated and lastUpdated field with milliseconds precision

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Storing dateCreated and lastUpdated field with milliseconds precision

Bhagwat Kumar
Hi,
 I am using grails(2.0.3) autoTimeStamp to store dateCreated and lastUpdated fields of a domain instance. We are using mysql database where I see the column type to be 'datetime'.

For dateCreated/lastUpdated, we need precision to the millisecond. However, when I do "domainInstance.dateCreated.time", the last three digits of the above output is always zero. So, while saving the object to the database, the millisecond part is truncated.

Is there any easy way/workaround to achieve this apart from adding another field of type long and using beforeInsert/beforeUpdate to update this field?


Thanks

Bhagwat Kumar
IntelliGrape Software Pvt. Ltd.
Reply | Threaded
Open this post in threaded view
|

Re: Storing dateCreated and lastUpdated field with milliseconds precision

Robert Fletcher-2
That's a limitation of MySQL. PostgreSQL supports millisecond precision on date time types.


On Thu, Dec 6, 2012 at 6:39 AM, Bhagwat Kumar <[hidden email]> wrote:
Hi,
 I am using grails(2.0.3) autoTimeStamp to store dateCreated and lastUpdated fields of a domain instance. We are using mysql database where I see the column type to be 'datetime'.

For dateCreated/lastUpdated, we need precision to the millisecond. However, when I do "domainInstance.dateCreated.time", the last three digits of the above output is always zero. So, while saving the object to the database, the millisecond part is truncated.

Is there any easy way/workaround to achieve this apart from adding another field of type long and using beforeInsert/beforeUpdate to update this field?


Thanks

Bhagwat Kumar
IntelliGrape Software Pvt. Ltd.

Reply | Threaded
Open this post in threaded view
|

Re: Storing dateCreated and lastUpdated field with milliseconds precision

Bhagwat Kumar
Thanks Robert. I am Going with the custom solution.

-------------------------
Bhagwat Kumar
IntelliGrape Software Pvt. Ltd.


On Thu, Dec 6, 2012 at 2:11 PM, Robert Fletcher <[hidden email]> wrote:
That's a limitation of MySQL. PostgreSQL supports millisecond precision on date time types.


On Thu, Dec 6, 2012 at 6:39 AM, Bhagwat Kumar <[hidden email]> wrote:
Hi,
 I am using grails(2.0.3) autoTimeStamp to store dateCreated and lastUpdated fields of a domain instance. We are using mysql database where I see the column type to be 'datetime'.

For dateCreated/lastUpdated, we need precision to the millisecond. However, when I do "domainInstance.dateCreated.time", the last three digits of the above output is always zero. So, while saving the object to the database, the millisecond part is truncated.

Is there any easy way/workaround to achieve this apart from adding another field of type long and using beforeInsert/beforeUpdate to update this field?


Thanks

Bhagwat Kumar
IntelliGrape Software Pvt. Ltd.


Reply | Threaded
Open this post in threaded view
|

Re: Storing dateCreated and lastUpdated field with milliseconds precision

littlej
In reply to this post by Robert Fletcher-2
mysql 5.6 fully supports datetime with milliseconds.  However, I have failed to find a way to get grails (gorm) to create a field of type datetime(3) for example (3 dp of millis) rather than the default which is no millis.