Click here to Skip to main content
15,888,320 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a table in mssql as "Messages"
I had set Zaman field as time(2) and auto fill with timestamp (getdate())
https://pasteboard.co/JO21lgJ.png
I'm executing and getting time as "hh:mm:ss" in MSSQL
https://pasteboard.co/JO264Vy.png
But When i call on asp.net MVC c# page i am getting times as "hh:mm:ss.XXXXXXXXX"
https://pasteboard.co/JO25CVGV.png
How can i solve this issue?

What I have tried:

I have no idea. I can clear with c# but why this isue?
Posted
Updated 12-Feb-21 5:56am
v2

If you don't want fractional seconds in your data, then don't create your column as time(2). The (2) indicates that you want 2 digits of fractional seconds. Instead, create the column as time(0).

If you just want to format the data to hide the fractional seconds, then you'll need to use a format string:
Standard TimeSpan format strings | Microsoft Docs[^]
Custom TimeSpan format strings | Microsoft Docs[^]
 
Share this answer
 
Comments
gacar 12-Feb-21 12:07pm    
Thank you very much. Now working well with time(0)
It's because times in SQL - and most other systems - aren't stored as years, months, days, hours , minutes, and seconds: they are stored as a number of "ticks" since a predefined point in time (which varies according to the system, it doesn't have to be a fixed point as long as the two systems know each others).

But those "ticks" aren't a even divisor of a second (or even the same on all systems), so when the time is converted from MSSql time(2) you won't get exactly what you might expect.
If you want to display a shortened time, then format the column in your presentation software to only show the info you want to see.
 
Share this answer
 
Comments
gacar 12-Feb-21 12:08pm    
Thank you. But time(0) in SQL solved my problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900