I am trying to declare a datetime variable with the value 1001-01-01 00:00:00.000
I have tried the following approaches with no luck
declare @d1 datetime = '1001-01-01';
declare @d2 datetime = 10010101;
declare @d3 datetime = '1001-01-01 00:00:00';
declare @d4 datetime = cast ('1001-01-01' as datetime)
I get the following errors
Msg 242, Level 16, State 3, Line 1
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Msg 8115, Level 16, State 2, Line 2
Arithmetic overflow error converting expression to data type datetime.
Msg 242, Level 16, State 3, Line 3
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Msg 242, Level 16, State 3, Line 4
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Is it possible to declare a datetime
variable which can hold the value 1001-01-01 00:00:00.000?
I recommend using it. This is not possible, because this is not a valid date in sql server. Sql server consider dates between 1753-01-01 and 9999-12-31. Check this link for more information: "DATETIME"
This is not possible, because this is not a valid date in sql server. Sql server consider dates between 1753-01-01 and 9999-12-31. Check this link for more information: "DATETIME" insert into my table (address, name, dateadded) values (?, ?, CASE WHEN ISDATE (?)=1 THEN ?
The earliest date that a datetime value can have is 1753-01-01. Recent versions of Sql Server have the data type datetime2 that has a larger range: Show activity on this post. The minimum SQL datetime is January 1,1753, so your date is indeed out-of-range.
The minimum SQL datetime is January 1,1753, so your date is indeed out-of-range. Show activity on this post. you will not be able to set a DateTime to that year, so you may want to store it as a string and leave it to the upper layer langague to deal with.
The minimum valid date for a DateTime
data type is January 1, 1753.
Try DATETIME2
, using:
DECLARE @d4 DATETIME2 = '1001-01-01'
The minimum valid date for DATETIME2
is 0001-01-01
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With