Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:42:01+00:00 2026-06-07T19:42:01+00:00

I have a table tblEmpDetail which contains a column CreatedDate . I want to

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:42:03+00:00Added an answer on June 7, 2026 at 7:42 pm

    No looping is required.

    SQL Server excels at doing “set based” queries.

    To get a projection:

    select
        CreatedDate,
        DateAdd(hour, 72, CreatedDate) [NewDate]
    from
        tblEmpDetail
    

    To update the table permanently:

    update
        tblEmpDetail
    set
        CreatedDate = DateAdd(hour, 72, CreatedDate)
    

    If you MUST have a loop, you can use a cursor:

    declare cur cursor fast_forward read_only for
    select
        CreatedDate,
        DateAdd(hour, 72, CreatedDate) [NewDate]
    from
        tblEmpDetail
    
    -- here, you would use the cursor.
    

    More information on cursors here: http://msdn.microsoft.com/en-us/library/ms180169.aspx

    EDIT

    Your query above can be done in a set based way like this:

    select
        CreatedDate,
        CASE
            WHEN DateAdd(hour, 72, CreatedDate) <= GetDate() THEN NULL
            ELSE DateAdd(hour, 72, CreatedDate)
        END [NewDate]
    from
        tblEmpDetail
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with data 1/1 to 1/20 in one column. I want the
I have table like below ID User Date Location 1 Tom 6-Mar-2012 US 2
I have table categories (c) and an another table (x) with a column which
I have table TB1 which has the following cols: ID | date --------------------- 1
I have table called FinalForgotten which only contains one field called aname. The field
i have table with 2 columns: date and points. I want to create a
I have table in which I am inserting rows for employee but next time
I have table and this table contain result column with some entries. I just
I have table table1 **************************** id | start_date | end_date 1 30/06/2012 01/01/9999 When
I have table with column Percentage varchar(10) Data in that table is Pecentage 2/10

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.