How do I return how many days are in the CURRENT month?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sskofid11
    New Member
    • Jul 2017
    • 5

    How do I return how many days are in the CURRENT month?

    (I'm a C# rookie) I want the same code to work, irrespective of what month we are in.

    I know the code for a specific month (DateTime.DaysI nMonth(int year, int month)) but what I am looking for is the code for the days in the current month (i.e. that corresponds to the current date/time on my computer/in my time zone)

    Regards
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    You're very close already. Here is the answer: DateTime.DaysIn Month(DateTime. Today.Year, DateTime.Today. Month)

    Here is an example:
    Code:
            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show(DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month).ToString());
            }

    Comment

    • sskofid11
      New Member
      • Jul 2017
      • 5

      #3
      Thank you very much. I tried this and it worked just fine.

      Comment

      Working...