MS SQL Server Concepts and Programming Question:
Download Questions PDF

How To Enter Date and Time Literals in MS SQL Server?

Answer:

Date and time literals are entered as character strings enclosed in single quotes ('). The string must in one of the recognizable data and time formats. Some of the most commonly used formats are given in the following tutorial exercise:

-- Default format for query output
DECLARE @x DATETIME;
SET @x = '2007-05-19 22:55:07.233';
SELECT @x;
GO
2007-05-19 22:55:07.233

-- Default for string print output
DECLARE @x DATETIME;
SET @x = 'May 19 2007 10:55PM';
SELECT @x;
GO
2007-05-19 22:55:00.000

-- Europe default format
DECLARE @x DATETIME;
SET @x = '19-May-2007 22:55:07.233';
SELECT @x;
GO
2007-05-19 22:55:07.233

-- ISO8601 standard format
DECLARE @x DATETIME;
SET @x = '2007-05-19T22:55:07.233';
SELECT @x;
GO
2007-05-19 22:55:07.233


Download MS SQL Server Interview Questions And Answers PDF

Previous QuestionNext Question
How To Enter Binary String Literals in MS SQL Server?Why I Can Not Enter 0.001 Second in Date and Time Literals in MS SQL Server?