Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How can we get total days of the month?

How can we get total days of the month?

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ATC
    wrote on last edited by
    #1

    In VB.net when we define DaySel as: Dim DaySel As Date then when we use the command totaldays = DaySel.DaysInMonth(DaySel.Year, DaySel.Month) it will response the corresponding days of the selected month (28 or 29 or 30 or 31 days) However when I define in VC# System.DateTime DaySel = default(System.DateTime); - I only can get DaySel.DayOfWeek or DaySel.DayOfYear Anyone can show me how to get the total days of the selected month? Thank for nay help :doh:

    L G 2 Replies Last reply
    0
    • A ATC

      In VB.net when we define DaySel as: Dim DaySel As Date then when we use the command totaldays = DaySel.DaysInMonth(DaySel.Year, DaySel.Month) it will response the corresponding days of the selected month (28 or 29 or 30 or 31 days) However when I define in VC# System.DateTime DaySel = default(System.DateTime); - I only can get DaySel.DayOfWeek or DaySel.DayOfYear Anyone can show me how to get the total days of the selected month? Thank for nay help :doh:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      // // Summary: // Returns the number of days in the specified month and year. // // Parameters: // year: // The year. // // month: // The month (a number ranging from 1 to 12). // int daysInMonthCnt = System.DateTime.DaysInMonth(int year, int month);

      1 Reply Last reply
      0
      • A ATC

        In VB.net when we define DaySel as: Dim DaySel As Date then when we use the command totaldays = DaySel.DaysInMonth(DaySel.Year, DaySel.Month) it will response the corresponding days of the selected month (28 or 29 or 30 or 31 days) However when I define in VC# System.DateTime DaySel = default(System.DateTime); - I only can get DaySel.DayOfWeek or DaySel.DayOfYear Anyone can show me how to get the total days of the selected month? Thank for nay help :doh:

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        The DaysInMonth is a static method, so you use the class name to call it, not a variable instance: DateTime.DaysInMonth(DaySel.Year, DaySel.Month) I don't know the exact reason why you can call static methods using a variable instance in VB, but it's not very logical.

        Despite everything, the person most likely to be fooling you next is yourself.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups