Click here to Skip to main content
15,887,386 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi please any one tell me how cann i save only time in sql server 2014 by using c#. i used store procedure for saving time
also explain me what is best datatype for Time attribute in database table.
In future i use this time for searching data.
and which one is best for save time using text box or datetime picker which one is best for getting time from user .
please explain this.
Thanks in advance

What I have tried:

i have no idea how can i do this
Posted
Updated 29-Nov-18 9:36am
Comments
ZurdoDev 29-Nov-18 15:26pm    
Use the TIME datatype.

1 solution

There is a TIME datatype: time (Transact-SQL) | Microsoft Docs[^] but ... convert it to UTC as part of your DateTime value in C# before you send it to SQL - if you don't, then you will be using local time which can be a real problem - it differs for two users in different countries, and it takes no notice of daylight savings.

Personally, I'd recommend storing it as a UTC date and time in a DATETIME2 column, and extract times as necessary - it makes comparisons a lot simpler in many ways.
 
Share this answer
 
Comments
Fahid Zahoor 30-Nov-18 9:35am    
and which one is best for sending time in database Datetime picker and Textbox???
OriginalGriff 30-Nov-18 9:58am    
DateTimePicker - it can't give you an "illegal date" unlike a textbox.
Fahid Zahoor 1-Dec-18 1:43am    
ok and in datetime i use 12 Hours or 24 Hours how can i differentiate AM and PM
OriginalGriff 1-Dec-18 4:02am    
A DateTiem value doesn't use 12 hours or 24 hours - it stores a number of "ticks" since a fixed point in time. AM / PM / 24 hour clocks are only relevent when converted from user input to DateTime or when converted from DateTime to user output for presentation - and then it depends on the user preferences what format is displayed, not the actual value.

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