2

I would like to know how to insert TIME into SQL Server using C#

I have a class that I use as a data layer:

    public class Main_Lom_Form
    {
        public string Specimen_ID
        public int Client_Key
        public string Outcome
        public string Medications
        public DateTime Date_Collected
        public DateTime Time_Collected

and I do not know if I should be declaring Time_Collected as DateTime?

What type should Time_Collected be so that if the time would be 13:05 it would be entered correctly into a column in SQL Server 2008 that is a TIME(7) datatype?

1

1 Answer 1

6
  • TimeSpan maps to time(7)
  • DateTime maps to datetime

If you only want to store time, then time(7) should be okay. Is there a reason why you don't combine Date_Collected and Time_Collected into one field of type datetime?

Sign up to request clarification or add additional context in comments.

2 Comments

in that case which datatype on sql server should i choose?
(Edited my comment into answer above.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.