I want to return the date a week ago from today

Discussion in 'C#' started by Rocket452, Apr 3, 2008.

  1. Rocket452

    Rocket452 New Member

    Joined:
    Apr 3, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I am using System.DateTime.Now.ToShortDateString() to get today's date.

    I want to return this date minus 7 days(a week ago) so I can use it as a parameter in a SQL query.

    I know that System.DateTime.Now has a Subtract method, but I dont think it will suit my purposes.

    thanks in advance
     
  2. praspam

    praspam New Member

    Joined:
    Feb 22, 2012
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    select cast(DATEDIFF(dd, 7, GetDate())as datetime)
     
  3. selvanshankar

    selvanshankar New Member

    Joined:
    Dec 8, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    India
    pls let me knw hw to substrct 7 days from today...
     
  4. medink

    medink New Member

    Joined:
    Jan 22, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I got this working

    DateTime today = DateTime.Today;
    DateTime back = today.Subtract(TimeSpan.FromDays(7));
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice