locked
Date Formatting - Date less than 6 months RRS feed

  • Question

  • hi,

    I have a requirement in which i need to get the Exactly Six months before date from getdate?

    if the getdate is 2012-11-28 i need to get 2012-05-28

    could anyone help me on this

    Thanks in advance..!!!



    Balaji - BI Developer

    Wednesday, November 28, 2012 4:13 AM

Answers

  • You can use DATEDIFF:

    SELECT DATEADD(month, -6, GETDATE()) AS SixMonthsAgo;
    Note that this will subtract the number of month boundaries from the specified date.  For example, for both 2012-12-30 and 2012-12-31, the resultant date will be 2012-06-30.


    Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/

    • Marked as answer by Balaji Prasad Wednesday, November 28, 2012 5:17 AM
    Wednesday, November 28, 2012 4:38 AM
    Answerer