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 2005 Forums
 Transact-SQL (2005)
 TO know No of years

Author  Topic 

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2010-06-23 : 07:27:48
hi i am having two values where both are converted from date to numeric value in milliseconds.i.e i wan to know date of birth

those are
487861200000
456325200000

the above one are now converted in milliseonds value.

from the difference of the above value i want to know the no of years.how can i do that?

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-06-23 : 07:45:45
Could this be it...? ->
DECLARE @date datetime = '1970-01-01 00:00:00'

SELECT DATEADD(SECOND, 487861200, @date)


- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-23 : 07:49:33
quote:
from the difference of the above value i want to know the no of years.how can i do that?

select (487861200000 - 456325200000) / 365.0 / 24.0 / 60.0 / 60.0 / 1000.0


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-06-23 : 08:09:44
Hm

SELECT DATEDIFF(year, getdate(), dateadd(second, (487861200000 - 456325200000)/1000, getdate()))

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2010-06-23 : 08:15:01
thanks
Go to Top of Page
   

- Advertisement -