how to calculate the number of days in a month using vb6.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandru8
    New Member
    • Sep 2007
    • 145

    #1

    how to calculate the number of days in a month using vb6.0

    hi to all
    if the current month is jan,i need to calculate the number of days of feb
    is it possible without assigning number of days manually to a variable
  • VACEPROGRAMER
    Banned
    New Member
    • Nov 2007
    • 167

    #2
    Of courese you can, but can you explain me what you going to do whit sample words . .. . Please

    VxE

    Comment

    • creative1
      Contributor
      • Sep 2007
      • 274

      #3
      To calculate # of days in current month

      Code:
      MsgBox DateAdd("m", 1, Now) - Now
      For any other month

      Code:
      Dim Date1 As Date
      Date1 = "01/03/2006"                ' for month of March
      MsgBox DateAdd("m", 1, Date1) - Date1
      It might help a little bit

      Regards

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Just for fun, here's another alternative. (There's almost always more than one way to accomplish things, in programming).

        [CODE=vb]Public Function DaysInMonth(ByV al Yr As Long, ByVal Mnth As Long) As Long
        ' Return the number of days in the specified month.
        DaysInMonth = Day(DateSerial( Yr, Mnth + 1, 1) - 1)
        End Function[/CODE]Of course, given that it's a single calculation, there may not be much point putting it in a function. Also, note that I just use Long data type wherever possible, for efficiency purposes. What you use is up to you. :)

        Comment

        • nagarchetan
          New Member
          • Mar 2013
          • 1

          #5
          To calculate # of days in current month

          Code:
          Private Sub cmdGo_Click()
          Dim month_number As Integer
          Dim year_number As Integer
          
              month_number = Month(txtMonth.Text)
              year_number = Year(txtMonth.Text)
              MsgBox "Days: " & Format$(Day(DateSerial(year_number, _
                  month_number + 1, 0)))
          End Sub
          Chetan Nagar
          Last edited by Rabbit; Mar 14 '13, 04:13 PM. Reason: Please use code tags when posting code.

          Comment

          Working...