Answers

Question and Answer:

  Home  MS SQL Server

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

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

 149 views

More Questions for you: