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
BedrockMission!

Learn More

View all

Sign in to view all badges

problem with date

Avatar

Avatar
Validate 1
Level 2
ibwaheemi
Level 2

Like

1 like

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 2
ibwaheemi
Level 2

Like

1 like

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
ibwaheemi
Level 2

27-11-2008

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

xfa.host.messageBox(Check the customers age they may be over 18!)

endif



--------------------------------------------------------------------------



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

Replies

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

28-11-2008

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'



//xfa.host.messageBox(dob.rawValue)

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

xfa.host.messageBox("Check the age ...you may be over 18!")

endif

Avatar

Avatar
Validate 1
Level 2
ibwaheemi
Level 2

Like

1 like

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 2
ibwaheemi
Level 2

Like

1 like

Total Posts

31 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
ibwaheemi
Level 2

28-11-2008

Paul your improved code worked a treat



again youved help me 😉



you are a diamond in a heap of stones



thank you

Avatar

Avatar
Level 3
_James_J_Gallag
Level 3

Likes

0 likes

Total Posts

54 posts

Correct Reply

0 solutions
View profile

Avatar
Level 3
_James_J_Gallag
Level 3

Likes

0 likes

Total Posts

54 posts

Correct Reply

0 solutions
View profile
_James_J_Gallag
Level 3

15-12-2008

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);

xfa.host.messageBox(diff);

}



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()

Avatar

Avatar
Level 3
_James_J_Gallag
Level 3

Likes

0 likes

Total Posts

54 posts

Correct Reply

0 solutions
View profile

Avatar
Level 3
_James_J_Gallag
Level 3

Likes

0 likes

Total Posts

54 posts

Correct Reply

0 solutions
View profile
_James_J_Gallag
Level 3

15-12-2008

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

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

15-12-2008

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.