Get SYSdate in SQL Server 2008 r2

Posted on 2011-05-04
Last Modified: 2012-05-11
I want to get t he sysdat and subtract 6 days from it
then put that date into a variable to use in my SELECT
so I only get order < Sdate
Question by:jaymz69
    LVL 32

    Expert Comment


    declare @sdate datetime

    set @sdate = DATEADD(DD, -6, GETDATE())
    LVL 29

    Assisted Solution

    by:Paul Jackson
    Declare @SDate DateTime
    Select @SDate = DateAdd(d,-6, GetDate())
    LVL 32

    Assisted Solution


    or to remove the time portion as well

    declare @sdate datetime

    SET @sdate = DATEADD(DD, -6, DATEDIFF(DD, 0, GETDATE()))
    LVL 42

    Accepted Solution

    why use a variable?  

    select ... from ... where order < Dateadd(dd,-6,datediff(dd,0,getdate()))

    Author Comment

    Even better if it can be done within the SELECT. I am going off my experance in another program, VFP

    Author Closing Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    restore daily backup 5 52
    SQL .Write 3 35
    sql help 5 42
    SQL Query Syntax:  Why is the CTE Pulling in More Data Than Asked For? 5 37
    After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
    How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now