Could someone please tell me if there is a Formcalc or Javascript equivilent of =now() in Excel? I know there is that time function, but that seems to come out with a long number that doen't mean anything to me. I want to be able to tab into a field, and the field show the current system time in HH:MM format.
Thanks.
Solved! Go to Solution.
Views
Replies
Total Likes
Views
Replies
Total Likes
In JavaScript you would use the Date object:
// Create variables
var currentDate;
var hours;
var minutes;
var formattedTime;
// Get time
currentDate = new Date();
hours = currentDate.getHours();
minutes = currentDate.getMinutes();
// Format time
if (hours < 10) { hours = "0" + hours };
if (minutes < 10) { minutes = "0" + minutes };
formattedTime = hours + ":" + minutes;
// Display formatted time
this.rawValue = formattedTime;
In your case, you would put this script in the 'enter' event of your field.
If you are doing this across multiple fields, it would make sence to implement this as a function in a script object.
Ben Walsh
JavaScript
var date = new Date();
this.rawValue = date.getHours() + ":" + date.getMinutes();
or
var date = new Date();
var hours = date.getHours();
if (hours > 12) {
this.rawValue = (hours - 12) + ":" + date.getMinutes() + " PM";
}
else {
this.rawValue = hours + ":" + date.getMinutes() + " AM";
}
Views
Replies
Total Likes
Unfortunately I can't get any of these to work. What am I doing wrong?
Views
Replies
Total Likes
Take a look at the attached. It contains 'Ben' time and 'Steve' time.
Views
Replies
Total Likes
"Queued"
Views
Replies
Total Likes
The virus scanner takes a while to release attachments. Send an email to stwalker.adobe@gmail.com and I will forward the sample.
Views
Replies
Total Likes
Check the settings in your script editor.
It is common to have the wrong Language set - it should be 'JavaScript'. This defaults to 'FormCalc' until you change it in your form properties (File>Form Properties>Defaults).
It should look like the screenshot below with either 'Ben' time or 'Steve' time:
Ben Walsh
Views
Replies
Total Likes
I can get it to work in a single cell, but not in my table.
Views
Replies
Total Likes
email is advanta@advantacf.com.au.
Views
Replies
Total Likes
I have attached a new sample that includes the calculations in a table. I will forward to email as well.
Wouldn't Formcalc be a little easier?
$ = Num2Time(Time(), "HH:MM")
Views
Replies
Total Likes
Thanks Jono - That did it!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies