CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Dates

  1. #1
    Join Date
    Aug 1999
    Posts
    17

    Dates

    Is there a method in VB if I pass in a month and year it will tell me the number of days in the month?


  2. #2
    Guest

    Re: Dates

    Well I have a vague idea that it can be done using the calendar property.
    Declare a variable as calendar and then try.I hope you can find your way out!!!


  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Dates

    You need to look at the 'DateDiff' function in VB (in the help). Here's a quick example :


    Dim dteStartDate as date
    Dim dteEndDate as date

    dteStartDate = CDate("01 Feb 1999") ' could use #2/1/1999
    dteEndDate = CDate("01 Mar 1999") ' could use #3/1/1999

    MsgBox DateDiff("d", dteStartDate, dteEndDate)




    This shows the number of days between the two dates (and hence in the month).


    Chris Eastwood

    CodeGuru - the website for developers
    http://www.codeguru.com/vb

  4. #4
    Join Date
    Aug 1999
    Location
    India, West Bengal
    Posts
    36

    Re: Dates

    A simple way to implement this is to move to the 1st of the next month and -1 a day to find the max nos of days this month using the dateadd function.

    Ex : =

    curr_dt = '1/9/99'
    last_DATE = DateAdd("D", -1, (DateAdd("M", 1, curr_dt)))






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured