Results 1 to 6 of 6

Thread: Date "Difference" function? WHAT?????

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    42

    Question Date "Difference" function? WHAT?????

    Can this be done?

    I have information about a customer (name, address, DOB etc) which i store in an array

    Evertime time i save the customer details, i need something to tell me if the person is over 21 years of age...............is there any way to do this.

    I have done everything on my project..............EXCEPT this.

    I have looked at all the sources i an find...but to no avail.

    Do i use something like Date difference or something , please help.

    I have come so far only to fail at this hurdle................aaggggghh!


    Thanks

  2. #2

  3. #3
    Member
    Join Date
    Nov 2002
    Location
    San Antonio, TX
    Posts
    35
    You can use the DateDiff() function:

    DateDiff("yyyy", DOB, Now())

    Where the first argument is the interval you want returned,
    the second argument is the earlier date, and the last argument
    is the later date. You can refer to MSDN for the specifics of
    the different intervals.

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    42
    sorry, i cant seem to get that to work

    culd you please elaborate.

    I have 2 dates.....the customers date of birth and the current date.

    How would using the difference between the 2 dates find out if the customer is over 21?

  5. #5
    Fanatic Member
    Join Date
    Nov 2001
    Location
    Bangkok
    Posts
    969

    Hi, here is the solution for a Agecheck!

    Excuse my sloopy way to write it, but I am lazy.


    txtBirthday = the Birthday of the person
    21 is in this example the Year to check
    It works exactly on the day!

    Private Sub Command2_Click()

    MsgBox CheckAgeInYears(CDate(txtBirthday), 21)

    End Sub

    Private Function CheckAgeInYears(datDate, numCheckAge)

    datCompareDate = Format(DateAdd("yyyy", numCheckAge, datDate), "dd.mm.yyyy")

    MsgBox datCompareDate

    If Format(datCompareDate, "yyyymmdd") > Format(Date, "yyyymmdd") Then
    CheckAgeInYears = "Not Ok"
    Else
    CheckAgeInYears = "Ok"
    End If

    End Function



    nice greetings
    Franky

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by DontKnowAnythin
    sorry, i cant seem to get that to work

    culd you please elaborate.

    I have 2 dates.....the customers date of birth and the current date.

    How would using the difference between the 2 dates find out if the customer is over 21?
    Try this:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim DOB As Date
    5.     Dim sDOB As String
    6.    
    7.     sDOB = InputBox("Type your date of birth")
    8.     If Len(sDOB) Then
    9.         DOB = CDate(sDOB)
    10.    
    11.         If DateDiff("yyyy", DOB, Now()) < 21 Then
    12.             MsgBox "Dude... you're too young!!!"
    13.         End If
    14.     End If
    15.        
    16.  
    17. End Sub
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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