Date datatype in sql server 2012
Defines a Date.
Range: 0001-01-01 to 9999-12-31
Format:YYYY-MM-DD.
YYYY is four digit from 0001 to 9999 yr |
MM is two digit from 01 to 12 months |
DD is two digit from 01 to 31 Days |
Storage : 3 bytes.
Daylight Savings aware | No |
Timezone Offset | No |
User defined fraction second precision | No |
Default value: | 1900-01-01 |
Create Table dateDemo
(
ID int idenitity,
joinDate Date
)
Insert Values into Date Column
Example 1:
/* Inserts today's date into date Column */insert into datedemo(joindate) values(GetDate());
select * from datedemo;
Example 2:
Insert into datedemo(joindate) values('');
Example 2 inserts Default value for the Date Data type column, i.e 1900-01-01.Refer
ID joinDate
1 2013-02-06
2 1900-01-01
Example 3:
Insert using variables.
declare @dt datetime='2020-12-31'
Insert into datedemo(joindate) values(@dt)
Insert into datedemo(joindate) values(@dt)
Example 4:
Insert using String value
Convert String to date value.
insert into datedemo(joindate) values(convert(date,'2013-12-12'))
Select * from datedemo
ID joinDate
1 2013-02-062 1900-01-01
3 2020-12-31
4 2013-12-12
Tags:Date datatype in sql server 2012,Date Default value,Insert String into date datatype column,Insert using Date variable,Get Today's date in SQL Server 2012.Date Storage,date Default Format,Insert on Date Column
No comments:
Post a Comment