Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6217419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:25:24+00:00 2026-05-24T07:25:24+00:00

Here’s one more or less for perfection’s sake. Microsoft SQL Server only contains the

  • 0

Here’s one more or less for perfection’s sake.

Microsoft SQL Server only contains the field type datetime for storing dates and times.

But let’s say that I want to store a list of business hours, where the date is completely irrelevant. Currently I’m using the datetime type and then simply displaying the time-portion of the data. But I have two problems with this.

  1. It seems awkwardly inefficient.
  2. It may confuse future developers to see a full-blown date coming along with the time, which they may not know whether is used anywhere or not.

And so it begs the question; in the absence of a specific time field (like in MySQL), what is the most optimal way of storing only a particular time of day, from 00:00 to 23:59?

UPDATE: It’s SQL Server 2005. (Also I’d just be interested in knowing what to do in general when there is no time type.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:25:25+00:00Added an answer on May 24, 2026 at 7:25 am

    For SQL Server 2005 or older…

    If you only want to know to the minute, you can store it as an int in the range of 1-1440. 1 is 00:01 and 1440 is 0:00.

    It would be easy do display as a time again if you like:

    SELECT CAST((605 / 60) as varchar) + ':' + RIGHT('0' + CAST((605 % 60) as varchar), 2)

    An additional advantage of this is that if you use a smallint data type you are saving 1-3 bytes per record from the built-in TIME datatype.

    TIME uses 3-5 bytes per row and smallint is 2 bytes per row.

    The extra bytes are for seconds and fractional seconds I believe.

    EDIT

    It’s more complicated with seconds but still doable I should think…

    1-86400 range (seconds per day)

    DECLARE @i INT
    SET @i = 3661
    
    SELECT RIGHT('0' + CAST((@i / 3600) as varchar),2) --hours
    + ':' + RIGHT('0' + CAST((@i % 3600)/60 as varchar), 2) -- minutes
    + ':' + RIGHT('0' + CAST((@i % 3600)%60 as varchar), 2) -- seconds
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my scenario. I've got SharePoint 2010 running on one server, with an SQL
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here is my HTML. Just a simple form: <form> Username: <input type=text id=username/> <br/>
Here's a dump of the stats provided my mod_pagespeed from one of my sites.
Here is the field declaration in a form: max_number = forms.ChoiceField(widget = forms.Select(), choices
Here's the problem....I have three components...A Page that contains a User Control and a
here is the scenario 1: user starts to type some word, autocomplete engine shows
here is my configuration: http://domain.com (obviously fictitious name...) hosted on a server running Apache
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.