views:

145

answers:

3

Hi, I want to find a date after a give weeks(months). For example, I want to find the date after 2 week from today or find the date after 4 month from today.

Thanks

+2  A: 

do you want like ?

DateTime dt = DateTime.Now.AddDays(14);
        DateTime dt1 = DateTime.Now.AddMonths(4);
Muhammad Akhtar
+2  A: 
DateTime.Now.AddDays(14)

to get the date 2 weeks from now

or

DateTime.Now.AddMonths(4)

to get the date 4 months from now

NB: This has nothing to do with ASP.NET. DateTime is part of the .NET BCL.

pmarflee
+2  A: 

Two weeks after today:

DateTime.Now.Date.AddDays(2*7)

Four months after today:

DateTime.Now.Date.AddMonths(4)

Use DateTime.Date if you want only the date without current time (as in the sample).

Dmytrii Nagirniak
+1 for 2 * 7. :)
Jakob Gade
Thanks :) 2*7 will be optimised by compiler but for a human reading the code is a bit easier to understand, especially if there should be something like 13 weeks
Dmytrii Nagirniak