Bobcares

SQL Server SmallDateTime: Explained

by | Nov 14, 2022

Let us learn more about the SQL server smalldatetime and how to use it. With the support of our MSSQL support services at Bobcares, we can give you a detailed note on how to use it.

 

DateTime & SmallDateTime in SQL Server

SQL server Smalldatetime

DateTime and SmallDateTime are data types that hold both date and time in the SQL server. The time is measured in 24-hour increments.

 

SQL SMALLDATETIME Data Type

The SMALLDATETIME data type gives a date and time of day. Dates from 1900-01-01 to 2079-06-06 are supported by SMALLDATETIME.

 

The default value is 1900-01-01 00:00:00.

 

The seconds are always set to zero, and fractional seconds are not taken into account.

 

SmallDateTime in SQL Server

Fractional seconds are ignored, and the seconds are always set to zero.

 

Any numbers entered in seconds that are up to 29.998 are rounded to the closest minute. Over 29.999 seconds, the numbers are rounded up.

 

DateTime Vs SmallDateTime

 

 

 

The table below illustrates the distinctions between DateTime and SmallDateTime.

 
  DateTime SmallDateTime
Syntax
datetime
smalldatetime
Usage
CREATE TABLE Table1 ( Column1 datetime )
CREATE TABLE Table1 ( Column1 smalldatetime )
Date range
1753-01-01 to 1999-12-01
1900-01-01 to 2079-06-06
Time range
00:00:00.000 through 23:59:59.997
00:00 through 23:59
Storage size
8 bytes
4 bytes, fixed
Accuracy
Rounded to increments of .000, .003, or .007 seconds
One minute
Default value
1900-01-01 00:00:00
1900-01-01 00:00:00
 

DateTime Examples

 

Creating DateTime & SmallDateTime Columns

The table below illustrates the distinctions between DateTime and SmallDateTime. 

 
123456
CREATE TABLE Table1 (    Column1 datetime ,   Column2 SmallDateTime)
 

Creating DateTime & SmallDateTime Columns

Inserting Values to DateTime & SmallDateTime Columns:

 
12345678910
Insert into Table1 (Column1, Column2) Values ('2020-12-21 12:40:53','2020-12-20 12:40:53' )Select * From Table1----------------------- ------------------- 2020-12-21 12:40:53.000 2020-12-20 12:41:00
 

Local Variables

123456789
DECLARE @varDateTime datetimeDECLARE @varSmalldatetime smalldatetime;SET @varDateTime = '2020-12-21 12:40:53';SET @varSmalldatetime ='2020-12-21 12:40:53';SELECT @varDateTime,   @varSmalldatetime;
 

Default Date & Time

After that, both DateTime & SmallDateTime always contains date and time. If we do not provide the time, then it defaults to 00:00:00.

 
123456789
Insert into Table1 (Column1, Column2) Values ('2020-12-21','2020-12-21' )Column1                 Column1         ----------------------- --------------------2020-12-21 00:00:00.000 2020-12-21 00:00:00

 

 

If no dates are specified, the date 1900-01-01 is used as the default.

 
123456789
Insert into Table1 (Column1, Column2) Values ('20:50:50.3','20:50:50.3' )Column1                 Column1         ----------------------- --------------------1900-01-01 20:50:50.300 1900-01-01 20:51:00
 

Range

Both of these data formats have a restricted range. The smallest date you can enter into a DateTime is 1753-01-01, while the smallest date you can insert into a SmallDateTime is 1900-01-01.

 
12345678910
Insert into Table1 (Column1, Column2) Values ('1753-01-01','1900-01-01' )Select * from Table1Column1                 Column2----------------------- ------------------- 1753-01-01 00:00:00.000 1900-01-01 00:00:00
 

[Need assistance with similar queries? We are here to help]

 

Conclusion

To conclude we have now learned more about the SQL server smalldatetime. We have also learned how to use it with the support of our MSSQL support services at Bobcares.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

     

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF