I have a table tblEmpDetail which contains a column CreatedDate.
I want to add 72 hours to each created date, so if the created date is 2012-07-14 07:21:19.180 then I want the output to be 2012-07-17 07:21:19.180.
Can someone let me know how can I accomplish to this?
Actually what I want to do is to go to each row then check if the
getdate() - createddate
is equal to or less than 72 hours; then I need to add 72 hours to createddate. Otherwise I want that column to be null. I am pasting my code that what I have done.
Declare @PassedTime datetime
set @PassedTime= DATEDIFF(HH,Createddate, GETDATE())
if CONVERT(varchar(20),@PassedTime,108)>=CONVERT(varchar(20),'72:00:00',108)
begin
select empno,empName,CreatedDate,dateadd(HH,72,CreatedDate)BD from tblEmpDetail
end
else
begin
select empno,empName,CreatedDate,'' as BD from tblEmpDetail
end
GetDate()once and saving the value instead of chasing a moving target in the query.