Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Int to Datetime (datediff)

Author  Topic 

Fatalsniper
Starting Member

45 Posts

Posted - 2005-08-24 : 16:54:39
Hey there,

Is there a way to convert an integer field to Datetime.

Example: input: 1992 (Integer)

if I can convert 1992(int) to 1/1/1992 (datetime) I could use
datediff(year, integerYear, getdate()), to be able to know the years between integerYear and getdate()

Thanks in advance...

SamC
White Water Yakist

3467 Posts

Posted - 2005-08-24 : 17:01:49
SELECT YEAR(GETDATE()) - integerYear

or, if it must be done another way...

SELECT DATEDIFF(yy, DATEADD(yy, integerYear - 1753, 'Jan 1 1753'), GETDATE())

May be buggy. I didn't test this.
Go to Top of Page

Fatalsniper
Starting Member

45 Posts

Posted - 2005-08-24 : 17:21:33
THANK YOU!
Go to Top of Page
   

- Advertisement -