Hi all,
I have my users DOB as a string (don't ask), how can I reliably check to see if they are over 18? Would I use DateDiff? How would I convert the string to a date first? The date is in dd/mm/yyyy format.
Many thanks Jonathan
Hi all,
I have my users DOB as a string (don't ask), how can I reliably check to see if they are over 18? Would I use DateDiff? How would I convert the string to a date first? The date is in dd/mm/yyyy format.
Many thanks Jonathan
Yep, you'll need CDate to convert your string and then DateDiff("yyyy",date1,date2) since you only really need the year.
Something like:
stringDate = "02/12/1990"
if IsDate(stringDate) then
document.write(DateDiff(yyyy, CDate(stringDate), Date()))
end if
VBScript's CDate function uses the current locale to convert the date. You may run into problems.
An alternative would be to do it the long way and parse the date out:
d = "02/05/1984"
sYear = cint(right(d,4))
sMonth = cint(mid(4,2))
sDay = cint(left(d,2))
ds = DateSerial(sYear, sMonth, sDay)
Now you can do your DateDiff:
if ( DateDiff( "yyyy", d, ds ) > 18 ) ...