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

VoyTec 671 Reputation points
2021-09-11T08:18:38.973+00:00

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.

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,826 Reputation points
    2021-09-11T15:12:18.313+00:00

    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

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful