System.DateTime remove (day/week/month)

Posted on 2006-04-17
Last Modified: 2010-05-18
Hello.. how can i remove x days or x weeks or x month from a DateTime.
I saw AddDays, AddMonths.. but i can't find how to substract a specific number of day/week or month from a date.

The only workaround a found is something like that:
System.DateTime sysDt = System.DateTime.Now()
sysDt = System.DateTime.FromOADate(Convert.ToDouble(sysDt.DayOfYear - 2));

I've not test well. and i want to know if it exist any easier way to do that.
Thanks for your help..
Question by:jabcoco
    LVL 5

    Accepted Solution

    Just put AddDays(-1) or AddMonths(-1) to subtract one day or month.
    LVL 10

    Author Comment

    LVL 10

    Author Comment

    hum.. i will accept question later... i may have other question about remove/add week...
    LVL 6

    Assisted Solution

    You can also use TimeSpan....

    I don't have the IDE up right now (probably errors), but here's some code that might lead you in the right direction...

    public DateTime SubtractDaysFromDate(DateTime dt, int numDays)
        TimeSpan span = new TimeSpan(numDays, 0, 0, 0, 0);
         DateTime date = dt.Subtract(span);
         return date;

    DateTime dt = DateTime.Now;
    dt = SubtractDaysFromDate(dt, 5);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    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.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 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

    17 Experts available now in Live!

    Get 1:1 Help Now