Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

SOLVED

Time Formatting

Avatar

Level 1

Can anyone tell me how to make a field with a formula in it turn the product of the calculation into time format (HH:MM)? For example, say you have two fields; Field 1, into which you input data, and Field 2 which gets the data from the Field 1 and changes it to time format. You put the value of 0.75 into Field 1, and Field 2 is supposed to change it to 1:15 (1hr, 15mins).

I've tried making Field 2 a time field, but I can't get it to work. I've also tried to use that timefmt function, but either I don't know how to use it properly (more than likely), or it doesn't do what I want it to do.

I'd appreciate anyone's input.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

If your input field is DecimalField1, you could try this FormCalc in the calculate event of one field (bit of a around about way):

var nHour = Floor(DecimalField1)
var nMinutes = (DecimalField1 - nHour) * 60
var sMinutes = Round(nMinutes)

if (DecimalField1 == null or DecimalField1 == 0) then
    $ = null
else
    $ = Concat(nHour, ":", sMinutes)
endif

I am going to lie down now...

Have a good weekend!!

N.

View solution in original post

6 Replies

Avatar

Level 4

Why do you want this on a timefield? Is there a special reason???

Since it is calculated you may be able to achieve the result with strings in a textfield.

Avatar

Level 1

No, I do not need the field to be a date/time field - I just thought that might be a way of making it work.

I'd be grateful if you told me how to achieve your suggestion. I'm afraid I'm not an expert on scripting, and have practically no experience with it whatever. (an example might help)

Much appreciated.

Avatar

Level 4

First off:

1.5  = 1 h 30 mins

(Calculation: 1.5 /100*60)

I would suggest you aggain to make invisible fields. Since I am not really good in scripting too, I prefer this method because it's easier to check if the solution is right.

Field 1, exit:(dont know if you want this one visible)

if (this.rawValue != null)
{Dezimalfield2.rawValue = this.rawValue;}

Field 2, hours, has no after comma digits (invisible)

Field 3: minutes, calculate (invisible)

if(Dezimalfield1.rawValue - Dezimalfield2.rawValue <0)
{Dezimalfield2.rawValue = Dezimalfield2.rawValue -1;
this.rawValue = (Dezimalfield1.rawValue - Dezimalfield2.rawValue) *60}

if (Dezimalfield1.rawValue - Dezimalfield2.rawValue >0)
{this.rawValue = (Dezimalfield1.rawValue - Dezimalfield2.rawValue)*60}

if(Dezimalfield1.rawValue - Dezimalfield2.rawValue == 0)
{this.rawValue = "0"}

(didn't divide through 100 because these are the minutes and I give them to the next field as string)

TEXT Field 4: (the end; calculated; you can do the format of this and the other fields as you like them best; it's really simple)

if (Dezimalfield1.rawValue != null)
{this.rawValue = Dezimalfield2.rawValue + " h " + Dezimalfield3.rawValue + " min "}

most likly one of the others will get headache if he sees this and post you another version with variables and only one field ;D

(this was fun though)

Avatar

Former Community Member

If applicable try to generate the PDF using XML binding.

This way, the programmers can write out the data to the xml as a normal string which would (mostly) circumvent scripting. If the programmer writes out the time as a string to your XML file, all you have to do is bind the XSD to the xpd file and bind the xml-data (which is a string) to the TextField you want.

This will save you alot of time because javascript & formcalc are not really the most performant programming languages ever invented.

Batch processing of whatever data you need to one or multiple xml-files will go more accurately and will save time as this is very well documented in eg. java or .net programming languages. (HINT: If your xml-file reaches over 5000 rootnodes its advised to use multiple xml files as livecycle seems to slow down hugely when crossing this barrier.)

Read well: only if applicable to your situation.

Avatar

Correct answer by
Level 10

Hi,

If your input field is DecimalField1, you could try this FormCalc in the calculate event of one field (bit of a around about way):

var nHour = Floor(DecimalField1)
var nMinutes = (DecimalField1 - nHour) * 60
var sMinutes = Round(nMinutes)

if (DecimalField1 == null or DecimalField1 == 0) then
    $ = null
else
    $ = Concat(nHour, ":", sMinutes)
endif

I am going to lie down now...

Have a good weekend!!

N.

Avatar

Level 1

Thanks again Niall - You're a Legend!

(Thanks everyone else for your time, too)