Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server datatype to store only time field like 09:10 etc

I want to store the office starting time etc in my database.

The time I want to store is like 09:15 AM or 1:15PM etc

My question is what is the best way to store it?

For the time being I am using int in SQL Server.

And I am storing the data like 0915, 1605, 2305 (maybe I can use some sort of constraints too)

Is there any better and good way to do it.

Any help is appreciated.

like image 711
Moons Avatar asked Aug 13 '12 09:08

Moons


People also ask

Can I use time datatype to store only time?

If you are using SQL 2008 or newer, you can use TIME Datatype to store only time. What is the equivalent of TIME for sql server 2005 ?

What is the SQL Server time data type?

The SQL Server TIME data type defines a time of a day based on 24-hour clock. The syntax of the TIME data type is as follows: TIME [ (fractional second scale) ] Code language: SQL (Structured Query Language) (sql) The fractional second scale specifies the number of digits for the fractional part of the seconds.

How to store the time of a day in SQL Server?

Summary: in this tutorial, you will learn how to store the time of a day in the database by using SQL Server TIME data type. The SQL Server TIME data type defines a time of a day based on 24-hour clock. The syntax of the TIME data type is as follows: The fractional second scale specifies the number of digits for the fractional part of the seconds.

What is data type in SQL Server?

A data type is an attribute that specifies the type of data that these objects can store. It can be an integer, character string, monetary, date and time, and so on. SQL Server provides a list of data types that define all types of data that you can use e.g., defining a column or declaring a variable.


Video Answer


1 Answers

If you are using SQL 2008 or newer, you can use TIME Datatype to store only time.

like image 109
Himanshu Jansari Avatar answered Oct 08 '22 10:10

Himanshu Jansari