Have a Question?

If you have any question you can ask below or enter what you are looking for!



SQL inserting values

In which format we insert date & time value in a created table to get a correct result?

  Govind Maurya

The default format of date and time in SQL is : YYYY-MM-DD hh:mm:ss[.nnnnnnn]

Example1: Example for Date datatype

DECLARE @date date = '12-21-16';

DECLARE @datetime2 datetime2 = @date;

SELECT @datetime2 AS '@datetime2', @date AS '@date';

--Result  

--@datetime2                  @date

--2016-12-21 00:00:00.0000000 2016-12-21

Example2: Example of Time datatype

DECLARE @time time(7) = '12:10:16.1234567';

DECLARE @datetime2 datetime2 = @time;

SELECT @datetime2 AS '@datetime2', @time AS '@time';

--Result  

--@datetime2                  @time

----------------------------- ----------------

--1900-01-01 12:10:16.1234567 12:10:16.1234567

  Devbrat Tripathi       20 Jun 2016       1       0     

Post Your Answers:

Please use the CODE HIGHLIGHT Button to format/highlight your codes if any