This is a migrated thread and some comments may be shown as answers.

DateTime losing milliseconds on return

1 Answer 321 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gregory
Top achievements
Rank 1
Gregory asked on 09 May 2017, 09:03 PM
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!

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 11 May 2017, 01:34 PM
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.
Tags
Grid
Asked by
Gregory
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or