question

Voytec-6484 avatar image
0 Votes"
Voytec-6484 asked Voytec-6484 commented

UWP C# Date.Time.Now + x [days]

Hello,

I want to use date +[x days] like ex.: DateTime.Now.Day +7days; But when it reaches next month I want to add next month to DateTime.Now.Month; + DateTime.Now.LeftDay's;
Is it possible to use somehow a code to calculate date automaticlly, because using if's is a waste of time and space? - I would have to spend a lot of time building code with if's for every case.

Detail Description:
I want to show first 14 days for a room if it is available or not. So when I start with DateTime.Now.Day, and the next day DateTime.Now.Day +1; but if it is end of a month I want to DateTime.Now.Month +1 and then DateTime.Now.Day =1; and so on...

Is there a ready made code for this?

Please help, thank you.

windows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
1 Vote"
Castorix31 answered Voytec-6484 commented

I don't see exactly what you mean, because if I call AddDays, it increments the month if needed
For example :

 DateTime dtNow = DateTime.Now;
 DateTime dtNext = dtNow.AddDays(30);               
 string sString = string.Format("Today : {0:yyyy/MM/dd}\r\nToday + 30 days : {1:yyyy/MM/dd}", dtNow, dtNext);               
 ContentDialog msgBox = new ContentDialog()
 {
     Title = "Information",
     Content = sString,
     SecondaryButtonText = "OK"
 };
 await msgBox.ShowAsync();

And I get :

131264-adddays.jpg



adddays.jpg (19.2 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I think that's the answer, how simple...
Thanks @Castorix31
II'll check it out soon and mark it as an answer

0 Votes 0 ·