Expand my Community achievements bar.

SOLVED

date stamp

Avatar

Former Community Member

I have set up a date field on my form so that the date shows up automatically. Currently if i open the document today and save it, it has todays date.  Tomorrow if I open the form again, it has the previous day's date. I would like the date to always be current-showing the date the file was opened. Can anyone explain how to do this?

I am using the following script in the ready:layout event

= xfa.timeStamp

i have had responses to previous posts about this but it is still not working correctly.

this.rawValue

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I think there is a better approach. In the Object library if you scroll down to the Custom objects there is a current date object. If you drag this on and delete the previous object.

This has FormCalc in the layout:ready event, which will fire every time the form is opened (and more frequently, like when new objects added at runtime):

$.rawValue = num2date(date(), DateFmt(1))

Good luck,

Niall

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

Hi,

I think there is a better approach. In the Object library if you scroll down to the Custom objects there is a current date object. If you drag this on and delete the previous object.

This has FormCalc in the layout:ready event, which will fire every time the form is opened (and more frequently, like when new objects added at runtime):

$.rawValue = num2date(date(), DateFmt(1))

Good luck,

Niall

Avatar

Former Community Member

i am using javascript. can i still use what you suggested?

Avatar

Level 10

Hi,

If this is the only script in the layout:ready event of this date stamp, then I would be inclined to stick with FormCalc for dates (and times). You can use javascript in different events in the same object and elsewhere in the form.

The events are separate and can use different languages.

If you have javascript script in the layout:ready event already and you want to share the space with the date stamp then you can achieve the same effect with Javascript using new Date(), but it is more involved:

var oNow = new Date();

this.rawValue = oNow.getDate() + "/" + (oNow.getMonth()+1) + "/" + oNow.getFullYear() +

" @ " + oNow.getHours() + ":" + oNow.getMinutes() + ":" + oNow.getSeconds();

Note: Months are zero-based, hence the +1

I hope that helps,

Niall

Avatar

Former Community Member

Thank you for your help Niall.  I would like the date to show up in dd/mm/yyyy format, but right now it is shoing as mm/dd/yyyy. Do you know how to change this?

Avatar

Level 10

Hi,

If you are using the FormCalc then you can replace the preset pattern to your specific requirements:

$ = Num2Date(Date(), "DD/MM/YYYY")

This should work, out of the box.

The Javascript solution should work as it basically concatenates the parts of the date.

Good luck,

Niall