Expand my Community achievements bar.

Extremely novice question regarding entry of current date

Avatar

Former Community Member
Using LiveCycle v. 8. Just want a field to display the current date when the form is opened.



The field type is date/time. When selected, I have the script bar set to "DocReady" as the event and script language = FormCalc. Can't figure out what to put in the script line to make the field display the date.



Thanks for any help.
7 Replies

Avatar

Former Community Member
Hi Rob,



Place the following script in the "layout:ready" event. script laguage = JavaScript.



var months = new Array ("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");



var now = new Date();

var yyyy = now.getYear() + 2000 - 100;

var mm = now.getMonth(); mm = months[mm];

var dayNumber = now.getDate();

var dd;



if (dayNumber < 10)

{dd = "0" + dayNumber;}

else {dd = dayNumber;};



if (this.rawValue == null) this.rawValue = yyyy + "-" + mm + "-" + dd;



trust this will help.



Regards,



Chris Fourie

www.intelliform.co.za

Avatar

Former Community Member
Thank you Chris, but when I follow your instructions and paste in the code, my text box still doesn't display the date. No doubt I'm missing something.



Rob

Avatar

Former Community Member
Hi Rob,



send your email addres to chris.fourie@intellifrom.co.za and I will send you a sample form.



Regards,



Chris Fourie

www.intelliform.co.za

Avatar

Former Community Member
Hi Rob,

You can retrive current date and time using FormCalc. However date and time functions are separate in FormCalc, so that you have to concat date and time after retrive.



Concat(Num2Date(Date(), "YYYY-MM-DD"), " ", Num2Time(Time(), "HH:MM:SS"))



this script returns the current date and time in format "YYYY-MM-DD HH:MM:SS". You can change the formats also. But it needs capital letters for format types.

Regards,

Asiye Gunaydin

Avatar

Former Community Member
I have a form that has a button to add new rows to a table, and need for one of the columns to default to the current date. However, once the date has been added, I don't want it to change. Is this possible?

Avatar

Former Community Member
Hi Claudia,



make the date field readonly and place this script in the layout:ready event of the date field:



var months = new Array ("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");



var now = new Date();

//var dateFormat = util.printd("yyyy-mm-dd", now); //this works but produces an error message in the warnings window "util undefined"

//this.rawValue = dateFormat;

var yyyy = now.getYear() + 2000 - 100;

var mm = now.getMonth(); mm = months[mm];

var dayNumber = now.getDate();

var dd;



if (dayNumber < 9)

{dd = "0" + dayNumber;}

else {dd = dayNumber;};



if (this.rawValue == null) this.rawValue = yyyy + "-" + mm + "-" + dd;



Regards,



Chris Fourie

www.inteliform.co.za

Avatar

Former Community Member
Chris,



I found your current date script very helpful for a form that I am putting together. Is there a way that I would be able to do the same thing with the current time? We need our form to display the current date and time, but also be editable if the form is filled in at a later date/time.



Thanks for your help,



Jason