1 2 3 4 5 6 > >>   Sort: Rank

Converting Integers into Date and Time Values in SQL Server
Can Integers Be Converted into Date and Time Values in SQL Server Transact-SQL? Can integers be converted into date and time values? The answer is yes. The input integer will be used as the number of days relative to the base date: Jan 1, 1900. The time of the day will be set to 0, midnight of the d...
2017-02-22, 135👍, 0💬

Converting Date and Time Values into Integers in SQL Server
Can Date and Time Values Be Converted into Integers in SQL Server Transact-SQL? Can date and time values be converted into integers? The answer is yes. The resulting integer will be the number days relative the base date: Jan 1, 1900. The time of the day will be rounded to days. But there several ru...
2017-02-22, 133👍, 0💬

Adding and Removing Days on Date and Time Values in SQL Server
How To Add or Remove Days on Date and Time Values in SQL Server Transact-SQL? SQL Server 2005 only support two operators on data and time values: + (Add): Adding days to a date and time value. - (Subtract): Removing days from a date and time value. Note that to add or subtract days on a date and tim...
2017-02-22, 133👍, 0💬

Verify Time Precision in SQL Server Transact-SQL
How to verify the precession of the server system time in SQL Server Transact-SQL? You can run a WHILE loop to check the precision of server system time in Transact-SQL as shown below: DECLARE @var DATETIME2(7); DECLARE @count INT = 0; WHILE @count<100 BEGIN SET @count = @count + 1; SET @var = SY...
2017-02-22, 132👍, 0💬

Converting DATETIME and NUMERIC Values in SQL Server
Are DATETIME and NUMERIC Values Convertible in SQL Server Transact-SQL? Are datetime and numeric value convertible? The answer is yes. Here are the main rules on DATATIME and NUMERIC value conversions: During the conversion a DATETIME value will be treated as a NUMERIC value with the number of days ...
2017-02-22, 131👍, 0💬

DATEDIFF() - Calculating DATETIME Value Differences in SQL Server
How To Calculate DATETIME Value Differences Using the DATEDIFF() Function in SQL Server Transact-SQL? If you want to calculate the difference between two date and time values, you can use the DATEDIFF() function in the following format: DATEDIFF(datepart, startdate, enddate) returns INT: "startdate"...
2017-02-20, 149👍, 0💬

Incrementing or Decrementing Parts of DATETIME Values in SQL Server
How To Increment or Decrement Parts of DATETIME Values in SQL Server Transact-SQL? If you want to increment or decrement one part of a date and time value, you can use the DATEADD() function in the following format: DATEADD(datepart, number, date) returns DATETIME: "date" - the input date "number" -...
2017-02-20, 143👍, 0💬

DATEADD() Function Usage Examples in SQL Server
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for manipulating date and time values. The following tutorial exercise shows you some good DATEADD() usage examples: -- Incrementing 1 year on a leap date DECLARE @birth_date DATETIME; SET @birth_date = '20...
2017-02-20, 136👍, 0💬

Subtracting a DATETIME Value from Another DATETIME Value in SQL Server
Can a DATETIME Value Be Subtracted from Another DATETIME Value in SQL Server Transact-SQL? Can a datetime value be subtracted from another datetime value? The answer is yes. The subtract operation can be performed by the subtract operator (-) as: datetime1 - datetime2: Returning a DATETIME value cal...
2017-02-20, 134👍, 0💬

Date and Time Functions Supported by SQL Server 2005 in SQL Server
What Are the Date and Time Functions Supported by SQL Server 2005 in SQL Server Transact-SQL? SQL Server 2005 supports n character string functions: DATEADD(datepart, number, date) - Returning the same date and time value with one part added with the "number". DATEDIFF(datepart, startdate, enddate) ...
2017-02-20, 134👍, 0💬

Calculating Age in Days, Hours and Minutes in SQL Server
How To Calculate Age in Days, Hours and Minutes in SQL Server Transact-SQL? On many Web sites, news items or blog articles are displayed with a publishing data and time represented in days, hours and minutes. To do this you can use the DATEDIFF() function with a simple algorithm as shown in the tuto...
2017-02-14, 158👍, 0💬

Difference Between GETDATE() and GETUTCDATE() in SQL Server
What Is the Difference Between GETDATE() and GETUTCDATE() in SQL Server Transact-SQL? The difference between GETDATE() and GETUTCDATE() is time zone number of the SQL Server machine. The tutorial exercise below gives you a good example: DECLARE @local_time DATETIME; DECLARE @gmt_time DATETIME; SET @...
2017-02-14, 149👍, 0💬

Getting Parts of DATETIME Values as Integers in SQL Server
How To Get Parts of DATETIME Values as Integers in SQL Server Transact-SQL? Sometimes, you want to one specific part of a DATETIME value as an integer to be used in your own date and time calculations. This can be done by using the DATEPART() function in the following format: DATENAME(datepart, date...
2017-02-14, 147👍, 0💬

Getting Year, Month and Day Out of DATETIME Values in SQL Server
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL? You can use DATEPART() to get any part of the DATETIME value. But to get year, month and day, you can use 3 specific functions: YEAR(), MONTH() and DAY(). These functions are equivalent to DATEPART() as: YEAR(date) = D...
2017-02-14, 145👍, 0💬

Getting Month and Weekday Names from DATATIME Values in SQL Server
How To Get Month and Weekday Names from DATETIME Values in SQL Server Transact-SQL? In DATETIME values, the month part and weekday part have names. You can use the DATENAME() function to get the month name and weekday name from a DATETIME value in the following format: DATENAME(datepart, date) retur...
2017-02-14, 140👍, 0💬

Formatting Time Zone in +/-hh:mm Format in SQL Server
How To Format Time Zone in +/-hh:mm Format in SQL Server Transact-SQL? From the previous tutorial, you know how to calculate the time zone value by using GETDATE() and GETUTCDATE() functions. But how can you format that time zone value in a nice looking format like +05:45 or -04:00? Unfortunately, S...
2017-02-08, 171👍, 0💬

CONVERT() - Formatting DATETIME Values to Strings in SQL Server
How To Format DATETIME Values to Strings with the CONVERT() Function in SQL Server Transact-SQL? SQL Server 2005 offers no functions to format DATETIME values in your own format patterns. But it does provide you a number of pre-defined format patterns that you can use with the CONVERT(char_type, dat...
2017-02-08, 161👍, 0💬

Setting New Values to Parts of a DATETIME Value in SQL Server
How To Set Different Parts of a DATETIME Value in SQL Server Transact-SQL? In SQL Server, you can get different parts of a DATETIME value with the DATEPART() functions. But there is no function that allows you to set different parts to a DATETIME value. For example, you a date_of_birth column as DAT...
2017-02-08, 157👍, 0💬

Truncating DATETIME Values to Dates without Time in SQL Server
How To Truncate DATETIME Values to Dates without Time in SQL Server Transact-SQL? Assuming that you have some date and time, DATETIME, values, and you want to work with dates only. You want to truncate them to dates without time, or with time of 00:00:00.000. Again, SQL Server offers no simple solut...
2017-02-08, 153👍, 0💬

Working with NULL Values in SQL Server Transact-SQL
Where to find answers to frequently asked questions on Working with NULL Values in SQL Server Transact-SQL? Here is a list of frequently asked questions and their answers compiled by FYIcenter.com DBA team on Working with NULL Values in SQL Server Transact-SQL. Clear explanations and tutorial exerci...
2017-02-08, 152👍, 0💬

Assigning NULL Values to Variables or Columns in SQL Server
How To Assign NULL Values to Variables or Columns in SQL Server Transact-SQL? The rule for assigning NULL values to variables or table columns is simple: Use keyword "NULL" directly as normal values. "NULL" can be used in SET statements to assign NULL values to variables. "NULL" can be used in SET c...
2017-02-05, 169👍, 0💬

What Are NULL Values in SQL Server
What Are NULL Values in SQL Server Transact-SQL? A NULL value is a special value that represents an unknown value. SQL Server supports NULL values with the following features: All data types used for table columns support NULL values. In another word, NULL values can be stored in database tables. In...
2017-02-05, 164👍, 0💬

NULL Values Involved in String Operations in SQL Server
What Happens If NULL Values Are Involved in String Operations in SQL Server Transact-SQL? If NULL values are involved in string operations, the result will be string NULL values. The following tutorial script shows you some good examples: SELECT 'FyiCenter'+NULL; GO ---------- NULL SELECT LEN(NULL);...
2017-02-05, 158👍, 0💬

NULL Values Involved in Datetime Operations in SQL Server
What Happens If NULL Values Are Involved in Datetime Operations in SQL Server Transact-SQL? If NULL values are involved in datetime operations, the result will be datetime NULL values. The following tutorial script shows you some good examples: USE FyiCenterData; GO SELECT GETDATE()+NULL; GO -------...
2017-02-05, 157👍, 0💬

1 2 3 4 5 6 > >>   Sort: Rank