Thursday, March 8, 2012

Data casting, casting operations

Does anybody know how could I calculate the new date(adding @.c to @.b
or subtracting @.b to @.c), having for example a declaration like this:
DECLARE @.a CHAR(12)
DECLARE @.b DATETIME
DECLARE @.c INT
SET @.b='3.04.04';
SET @.c=6

and to calculate the number of days between two dates with this kind
of declaration(@.a-@.b or @.b - @.a):
DECLARE @.a CHAR(12)
DECLARE @.b DATETIME
DECLARE @.c INT
SET @.a='12.2.04';
SET @.b='3.04.04';

Thanks in advance.Take a look at the DATEADD and DATEDIFF functions in Books Online.
Don't specify dates in code in the format you have done. Use 'YYYYMMDD'
which will work safely regardless of regional server and connection
settings.

--
David Portas
SQL Server MVP
--

No comments:

Post a Comment