Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

problem with date


Level 2
i am trying to display an error message if a customer is over 18

----- topmostSubform.Page1.dob::exit: - (FormCalc, client) ---------------

//todays date

var today = num2date(date(), DateFmt(1))

//difference between today and date of birth 'dob'

var diff = today - Date2Num(dob.rawValue, "DD/MM/YYYY")

//is it over 18 years 18*365.25=6574.5

if (diff > 6574.5) then

//alert message the customers age they may be over 18!)



a textbox that displays the age would be enough but i dont think that is possible.
0 Replies


Level 10
Yes it is possible ...the date() function returns the number of days since the epoch so you do not need to wrap it in a num2date call. It should be:

var today = date()

I also do not think you shodul name your variable today. Change its name to something else. Here is the code that I used:

//todays date

var num_today = date()

//difference between today and date of birth 'dob'


var diff = num_today - Date2Num(dob.rawValue, "YYYY-MM-DD")

//is it over 18 years 18*365.25=6574.5

if (diff > 6574.5) then"Check the age may be over 18!")



Level 2
Paul your improved code worked a treat

again youved help me 😉

you are a diamond in a heap of stones

thank you


Level 3
I am trying to do something similar to the above in the exit event of a field:

if (this.rawValue != "")


var num_today = Date();

var diff = num_today - date2Num(this.rawValue);;


I am just outputting the difference to a message box just to view it myself but unfortunatlyu I'm experiencing a problem before I get that far.

When I exit the field I get the following action script error:

script execution error : MemberForm[0].#subform[4].subDependantList[0].subDependant[0].dob[0]:exit

ReferenceError: Error #1065: Variable Date2Num is not defined.

at xfamx.scripting::Node/execEvent()

at ga.model::PanelItem/focusOutHandler()

at flash.display::Stage/set focus()

at mx.core::UIComponent/setFocus()

at mx.managers::FocusManager/setFocus()

at mx.managers::FocusManager/mouseDownHandler()


Level 3
Ok I see that the Date2Num() function in only for formcalc. Is there a similar function in Javascript ??


Level 10
There is a function that returns the # of milliseconds from the epoch but you have to create a date object first. Do a google search of date arithmetic for javascript and you will see plenty of examples.