Results 1 to 5 of 5

Thread: Calculate Date

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    83

    Calculate Date

    Hello Friends
    I need to find out the difference between two dates

    the one i know is datediff but it gives me either No of days or year

    i want it to be in this fashion


    days/Months/Year

    in date format


  2. #2
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Calculate Date

    VB Code:
    1. Dim IYourAgeInDays As Long
    2. 'First you need to see if a valid date is entered.
    3. If IsDate(Text1.Text) Then
    4. whatevervariable = CDate(Text1.Text)
    5. 'then use DateDiff
    6. lYourAgeInDays = DateDiff("d", whatevervariable, Now) 'd = days
    7. lblAgeDays.Caption = CStr(lYourAgeInDays) 'put on label
    8. s = seconds
    9. yyyy = years
    10. m = months
    11.  
    12. Else
    13. MsgBox "Error"
    14. End If

    Hope it helps!
    VB.NET MVP 2008 - Present

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    83

    Re: Calculate Date

    It has given me the number of days but then to calculate it to years Month days was the Question

  4. #4
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Calculate Date

    Quote Originally Posted by vbcoder2
    It has given me the number of days but then to calculate it to years Month days was the Question
    Instead of: DateDiff("d", whatevervariable, Now) 'd = days
    Use DateDiff("m", whatevervariable2, Now) 'm = Months
    and DateDiff("yyyy", whatevervariable3, Now) 'yyyy = years
    VB.NET MVP 2008 - Present

  5. #5
    Registered User HellRaider's Avatar
    Join Date
    Sep 2003
    Posts
    70

    Re: Calculate Date

    Hello
    This should also get the answer in the format of dd/mm/yy. Hope its what ur after.
    VB Code:
    1. Text1.Text = Format(DateDiff("d", "1/2/02", "1/2/03", vbSunday, vbFirstJan1), "dd/mm/yy", vbSunday, vbFirstJan1)

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