|
-
Dec 7th, 2002, 11:29 AM
#1
Thread Starter
Member
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
-
Dec 7th, 2002, 11:58 AM
#2
Frenzied Member
Use the DateDiff function:
VB Code:
Dim lAge as Long
lAge = DaeDiff("yyyy", FirstDate, SecondDate)
-
Dec 7th, 2002, 11:59 AM
#3
Member
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.
-
Dec 7th, 2002, 12:16 PM
#4
Thread Starter
Member
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?
-
Dec 7th, 2002, 12:17 PM
#5
Fanatic Member
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
-
Dec 7th, 2002, 12:56 PM
#6
Need-a-life Member
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:
Option Explicit
Private Sub Form_Load()
Dim DOB As Date
Dim sDOB As String
sDOB = InputBox("Type your date of birth")
If Len(sDOB) Then
DOB = CDate(sDOB)
If DateDiff("yyyy", DOB, Now()) < 21 Then
MsgBox "Dude... you're too young!!!"
End If
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|