Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add 1 week to current date

Tags:

c#

datetime

I've got something like this DateTime.Now.ToString("dd.MM.yy"); In my code, And I need to add 1 week to it, like 5.4.2012 to become 12.4.2012 I tried to convert it to int and then add it up, but there is a problem when it's up to 30.

Can you tell me some clever way how to do it?

like image 453
René Beneš Avatar asked Apr 05 '12 21:04

René Beneš


People also ask

How to add 1 Week to current date in JavaScript?

Use date. getDate() to retrieve the defined days for the given date . Then add your desired weeks and adjust the date using the setDate() .

How would you change the date to one week later in JavaScript?

getDate() method. You can then go ahead and add 7 more days to increase the days by one week. Increase the days of a JavaScript date instance using the . setDate() method.

How to add two weeks to a date in JavaScript?

function addWeeks(numOfWeeks, date = new Date()) { date. setDate(date. getDate() + numOfWeeks * 7); return date; } // Add 2 weeks to current Date console. log(addWeeks(2)); // 👇️ Mon Feb 28 2022 console.

How to add days to a date in JavaScript?

The setDate() method can be used to add days to a date.


1 Answers

You want to leave it as a DateTime until you are ready to convert it to a string.

DateTime.Now.AddDays(7).ToString("dd.MM.yy");
like image 132
Guvante Avatar answered Oct 01 '22 06:10

Guvante