TSQL DATETIME
-
Hello guys, I am creating a database script and in this script i am declareing a datetime variable like below
DECLARE @ENDDATE DATETIME
Now my question is that i want to initialize the value of this variable and i am doing it this way
SET @ENDATE '30/12/2009'
and this is giving me an error saying that i cannot covert from char to datetime. How can this be done guys? Thank you in advance Regards, Christian Pace
-
Hello guys, I am creating a database script and in this script i am declareing a datetime variable like below
DECLARE @ENDDATE DATETIME
Now my question is that i want to initialize the value of this variable and i am doing it this way
SET @ENDATE '30/12/2009'
and this is giving me an error saying that i cannot covert from char to datetime. How can this be done guys? Thank you in advance Regards, Christian Pace
-
Hello guys, I am creating a database script and in this script i am declareing a datetime variable like below
DECLARE @ENDDATE DATETIME
Now my question is that i want to initialize the value of this variable and i am doing it this way
SET @ENDATE '30/12/2009'
and this is giving me an error saying that i cannot covert from char to datetime. How can this be done guys? Thank you in advance Regards, Christian Pace
The default format of a date in sql =
MM/dd/yyyy
, so 30/12/2009 is indeed an invalid date. So there are three ways to solve this:- Use
set DateFormat dmy
- use
set @EndDate = '12/30/2009'
- use
set @EndDate = '20091230'
The first option will allow you to use your own way of using dates. In the second option you use the current settings of the server. You cannot always be sure of this setting, so I wouldn't use this. The third option is using the ISO format for dates. I prefer this method because it is language independent.
Wout Louwers
- Use
-
The default format of a date in sql =
MM/dd/yyyy
, so 30/12/2009 is indeed an invalid date. So there are three ways to solve this:- Use
set DateFormat dmy
- use
set @EndDate = '12/30/2009'
- use
set @EndDate = '20091230'
The first option will allow you to use your own way of using dates. In the second option you use the current settings of the server. You cannot always be sure of this setting, so I wouldn't use this. The third option is using the ISO format for dates. I prefer this method because it is language independent.
Wout Louwers
- Use