SQL database Day and time


I am new to SQL and am adding a table that holds calendar details.
Should I use a separate column for Date and another for Time  (if so what data type)
or should I use one column for date and time (if so what data type)
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
Olaf DoschkeConnect With a Mentor Software DeveloperCommented:
Questions are:

What kind of a calendar do you have?
What do you want to store? date and time and timezone?
What queries of the data do you think of?

For example if you have a event calender and you want to enable users to search for events at a certain time range, say in the evening from 2000 to 2200, independant of the date, then you better store the time portion seperate. You can since sql 2008, as it offers the time data type.

If you need to compute differences from datetime 1 to datetime 2, then it's better to store date and time in a datetime field, depending on the precision you need smalldatetime or datetime.

Also, if the calender is storing times for different time zones, you can make use of the datetimeoffset data type.

Here's more in detail of the different date and time data types of sql server 2008:

Bye, Olaf.

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
I am storing school calendar events.
An example of one entry would be:

Nov 5
3:30 pm
U15 tennis finals
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks that link helped a lot
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.