none
C# Console Application- Question about using dates RRS feed

  • Question

  • What do I need to write in the code in order to print tomorrow's date on the screen?

    For example- today's date is 13/6/2018 so the system will calculate the date by itself and write tomorrow's date- 14/6/2018. Is that even possible?

    Wednesday, June 13, 2018 2:37 PM

Answers

  • For example :

    DateTime dtNow = DateTime.Now;
    DateTime dtNew = dtNow.AddDays(1);
    Console.WriteLine("Today: {0:dd/MM/yyyy}", dtNow);
    Console.WriteLine("Tomorrow: {0:dd/MM/yyyy}", dtNew);



    • Edited by Castorix31 Wednesday, June 13, 2018 2:46 PM
    • Proposed as answer by CoolDadTxModerator Wednesday, June 13, 2018 6:48 PM
    • Marked as answer by yuvalmus Friday, June 15, 2018 9:27 PM
    Wednesday, June 13, 2018 2:45 PM

All replies

  • For example :

    DateTime dtNow = DateTime.Now;
    DateTime dtNew = dtNow.AddDays(1);
    Console.WriteLine("Today: {0:dd/MM/yyyy}", dtNow);
    Console.WriteLine("Tomorrow: {0:dd/MM/yyyy}", dtNew);



    • Edited by Castorix31 Wednesday, June 13, 2018 2:46 PM
    • Proposed as answer by CoolDadTxModerator Wednesday, June 13, 2018 6:48 PM
    • Marked as answer by yuvalmus Friday, June 15, 2018 9:27 PM
    Wednesday, June 13, 2018 2:45 PM
  • Maybe, the following can help:
    Console.WriteLine($"{DateTime.Now.Date.AddDays(1).ToShortDateString()}");
    wizend
    Wednesday, June 13, 2018 2:47 PM