datediff function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cdm2883
    New Member
    • Sep 2007
    • 53

    datediff function

    i dont knot the code to calculate how old some one is in years and days.

    i have to make the code where i can eneter some ones birthdate and then calculate the years and days diffrent from the date that is now.



    Thank you,
    David Moore
  • YarrOfDoom
    Recognized Expert Top Contributor
    • Aug 2007
    • 1243

    #2
    Could you maybe specify where you want to use the code for, because I remember having to create the same code for school once. Nothing personal, just rules :P

    Yarr Of Doom

    Comment

    • cdm2883
      New Member
      • Sep 2007
      • 53

      #3
      Originally posted by yarrofdoom
      Could you maybe specify where you want to use the code for, because I remember having to create the same code for school once. Nothing personal, just rules :P

      Yarr Of Doom


      we have to let the person input thier name b-day and, thier height, so it needs to be up next to all of that. SOrry i am brand new at this, so im sorry if i am confusing!!

      Comment

      • YarrOfDoom
        Recognized Expert Top Contributor
        • Aug 2007
        • 1243

        #4
        I'm sorry cdm2883, but with "Nothing personal, just rules" I meant that the forums aren't here to have your homework done for you. But there's one tip I will give you (altough you probably found that yourself already): use date-variables.


        Yarr Of Doom

        Comment

        • kadghar
          Recognized Expert Top Contributor
          • Apr 2007
          • 1302

          #5
          Originally posted by cdm2883
          i dont knot the code to calculate how old some one is in years and days.

          i have to make the code where i can eneter some ones birthdate and then calculate the years and days diffrent from the date that is now.



          Thank you,
          David Moore
          sure define a date variable:
          dim d as date
          where the birthdate is set
          then just make a rest and place it wherever you want, lets say a message box:

          msgbox("You are " & date - d & " days old.")

          Hope that helps

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            Hi,

            Use DateDiff Function :

            [code=vb]
            MsgBox DateDiff("D",CD ate(txtDate), Date)
            [/code]

            If u want diff in Months, u can use "m" instaed of "D"
            and for years "Y"

            Regards
            Veena

            Comment

            • cdm2883
              New Member
              • Sep 2007
              • 53

              #7
              Originally posted by QVeen72
              Hi,

              Use DateDiff Function :

              [code=vb]
              MsgBox DateDiff("D",CD ate(txtDate), Date)
              [/code]

              If u want diff in Months, u can use "m" instaed of "D"
              and for years "Y"

              Regards
              Veena


              Thank you, but i am writing my code in a Console App. how would i do it without a Msgbox?!

              Thanks

              Comment

              • QVeen72
                Recognized Expert Top Contributor
                • Oct 2006
                • 1445

                #8
                Hi,

                Instead of Msgbox, Assign the result of "DateDiff" to a Numeric Variable..

                Regards
                Veena

                Comment

                Working...