These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Need Help with adding 30 minutes to a field

Fireball23
Registered: Apr 15 2011
Posts: 4
Answered

I have two DateTime Fields on a PDF. I just want the user to enter a time such as 2:15 in one box, and have the other box auto display 2:45. I've looked at lots of examples, and can not get anything working. Help please!
 
(I know the formula below is wrong - I've tried a lot of variations, and simplified it here to show what I'm trying to do ... I just need a simple example of what the formula should be.
 
topmostSubform.Page1.MyDateTimeField2::exit - (FormCalc, client)
if ($.rawValue <> null)then
MyDateTimeField3.formattedValue = Num2Time(MyDateTimeField2.value + 30, "HH:MM")
endif
 

- Ron

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You need convert the starting time string to a number using the "Time2Num" function. Then add 30 minutes converted to the same time unit as the value from the "Time2Num" function. And then convert that value to the formatted time string using the "Num2Time" function.

if (HasValue($))then
MyDateTimeField3.rawValue = Num2Time(Time2Num($.formattedValue, "HH:MM") + (30 * 60 * 1000), "HH:MM")
endif


In simpler format:

// default value if no entry or entry cleared
MyDateTimeField3.rawValue = null
// if we have a time entered
if (HasValue($))then
// get time in milliseconds
var nTime = Time2Num($.formattedValue, "HH:MM")
// add 30 minutes in milliseconds
nTime = nTime + (30 * 60 * 1000)
// convert milliseconds to HH:MM
MyDateTimeField3.rawValue = Num2Time(nTime, "HH:MM")
endif


George Kaiser

Fireball23
Registered: Apr 15 2011
Posts: 4
I've tried that, but the resulting field always shows "5:30 PM" no matter what I add to it ... I tried deleting both fields and inserting new fields to see if I had formatted something wrong. Still always "17:30" or "5:30 PM"

- Ron

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Are the form fields within the same subform?

Try:

if (HasValue($))then
xfa.host.messageBox(Num2Time(Time2Num($.formattedValue, "HH:MM") + (30 * 60 * 1000), "HH:MM"))
MyDateTimeField3.rawValue = Num2Time(Time2Num($.formattedValue, "HH:MM") + (30 * 60 * 1000), "HH:MM")
endif

You also might want to clear the result field if there is no time entered.

I also have the result field as a plain text field.

George Kaiser

Fireball23
Registered: Apr 15 2011
Posts: 4
Same problem ... if I remove the " + (30 * 60 * 1000)" part, I get a blank answer ...so my "Time2Num($.formattedValue, "HH:MM") " must not be working correctly ...

- Ron

Fireball23
Registered: Apr 15 2011
Posts: 4
I have uploaded a copy of my PDF to acrobat.com ... https://acrobat.com/#d=xgZ6Jh2wlYVkaQyzBYDuMA ... maybe you can see what's wrong with it?

- Ron

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Accepted Answer
Look at the format for your source date field. It is not the exactly the same as the format string you are providing for the conversion.

From the LiveCycle Designer Scriptting Reference for the Time2Num funciton:

The function returns a value of 0 if any of the following conditions are true:
• The format of the given time does not match the format specified in the function.

• Either the locale or time format supplied in the function is invalid.

Insufficient information is provided to determine a unique time since the epoch (that is, any information regarding the time is missing or incomplete.

George Kaiser