Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Store time as HH:mm format in table

Author  Topic 

sqlqueries
Starting Member

4 Posts

Posted - 2015-05-01 : 18:39:52
I have a requirement to store time exactly as HH:mm format in sql table. What should be the column data type? How can I store time in this format.

I have two text boxes - Start Time and End Time.
If i enter 6 and 45, time should be stored as 6:45 ( 24 hours format)
If i enter 18 and 45, time should be stored as 18:45 ( 24 hours format)

How can I achieve this?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-05-01 : 18:41:24
I'd use char data type, but I'd question the requirement.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sqlqueries
Starting Member

4 Posts

Posted - 2015-05-01 : 18:49:41
Certain features of a web application have to blocked and should be allowed in specific time alone. hence this requirement.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-05-01 : 18:54:00
quote:
Originally posted by sqlqueries

Certain features of a web application have to blocked and should be allowed in specific time alone. hence this requirement.



But the requirement shouldn't specify HOW it is stored. You should be using time data type and have the application transform it if needed. Times should be stored as TIME.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sqlqueries
Starting Member

4 Posts

Posted - 2015-05-01 : 19:11:36
Pictorial representation of requirement.

https://drive.google.com/file/d/0BzyP_16MeLGXNXhPX1I4VkhvVkE/view?usp=sharing

Can you give more detailing on data type and storage?

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-05-01 : 19:14:27
I still say you should use TIME data type. You can then display the required format by coding the convert in your application.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sqlqueries
Starting Member

4 Posts

Posted - 2015-05-01 : 19:17:03
Thank you very much Tara Kizer.
Go to Top of Page
   

- Advertisement -