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)
 how to change age in datetime

Author  Topic 

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2010-07-13 : 07:33:17
hi for exaample a person age is 28 how to reperesent it in sql server datetime field...

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-13 : 07:43:24
store his birthday: '19820713'


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2010-07-13 : 07:44:15
any query to do so........
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-07-13 : 07:49:01
Select convert(datetime,convert(varchar(20),dateadd(yy,-28,getdate()),110))


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-13 : 07:50:23
update table
set DayOfBirth = dateadd(yy,-28,getdate())
where person=...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-07-13 : 08:09:01
quote:
Originally posted by webfred

update table
set DayOfBirth = dateadd(yy,-28,getdate())
where person=...


No, you're never too old to Yak'n'Roll if you're too young to die.



But this will have the time part included.


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-13 : 08:11:27
quote:
Originally posted by Idera

quote:
Originally posted by webfred

update table
set DayOfBirth = dateadd(yy,-28,getdate())
where person=...


No, you're never too old to Yak'n'Roll if you're too young to die.



But this will have the time part included.


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH


You are right



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-13 : 08:12:29
(dateadd(yy,-28,dateadd(d,datediff(d,0,getdate()),0)))


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -