DateTime losing milliseconds on return

2 posts, 0 answers
  1. Gregory
    Gregory avatar
    27 posts
    Member since:
    Feb 2014

    Posted 09 May Link to this post

    Anyone know why my DateTime is losing milliseconds when returning back to the server from a grid? E.g. I use Entity framework to select a SQL DateTime value (UTC) and populate a Kendo grid. Then during the grid's update event if I check the date it seems to have lost its milliseconds. I'm trying to use this for concurrency checking and it needs to be precise. Any ideas would be greatly appreciated!
  2. Georgi
    Admin
    Georgi avatar
    146 posts

    Posted 11 May Link to this post

    Hi Gregory,

    Unfortunately the DateTimePicker ignores the milliseconds and you can't use it for the precision you need.
    However as a workaround you can use MaskedTextBox to restrict the input from the client and use the date as a string in your ViewModel. You can still map it to DateTime object and use it as a date in your database. Adding a placeholder to the text box will make it more clear what is the format of the input. But because you are using it as a string you will have to do an additional check at the server if the date is in the correct format.

    In the link below you can read about the MaskedTextBox.


    I have attached a sample (PreciseTime.zip) project of how I managed to do it. You don't have to do it the same way, but you can use the logic and apply it using best practices and enough guard clauses.


    Regards,
    Georgi
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top