Expand my Community achievements bar.

How do I work with dates?

Avatar

Former Community Member

I've tried several formcalc and javascript methods, but none of them have worked for me so far.  What I want to do is take the current date and extract the month and year.  Then I will use these to test against other values.  An alternative is to build some dates and compare them to the current date.  That date can be changed by the user after the initial display of the form.

In psuedo code it would look like this:

// currently in the minimum wage field

// MonthYear field is initially set to the current date, but can be changed by the user

var curDate = MonthYear;

var prior10Date = "07/01/2010";

var prior09Date = "07/01/2009";

if (curDate > prior10Date) then

     this.rawValue = 8.25;

else

if (curDate > prior09Date) then

     this.rawValue = 8.00;

else

     this.rawValue = 7.75;

7 Replies

Avatar

Former Community Member

Moderators - please delete this as it is in the wrong forum.

Avatar

Former Community Member

Thanks for the reply.  I've asked the forum moderators to delete the thread as I foolishly put this message in the wrong place.  I'm reposting it in the Designer forum.

BTW, I get an error when I try to post the value to the field.  "syntax error near token minWage":

this = minWage;

Avatar

Level 4

The code I supplied is Javascript,  if minWage is the field you are in, i.e., Form.subform.minWage::exit(Javascript), you will want your value setting to be:

or if minWage is a variable within scope of the script, then:

If you give me the whole section, or upload your form to Acrobat.com I can help you out further.

Thanks,

Alex

The moderators will probably just move the thread, so filling out this one is still fine.

Avatar

Former Community Member

I've tried it both ways (formcalc and javascript).  Here is the current version:

// WVSWEW.WEWsubform.StateMinimumWage::initialize

// JavaScript Client

// workDate will be set to another field (datetime format) that the user

// can modifiy and the whole form updated with new values at that time

var workDate = new Date();
var prior10Date = new Date(2010,07,01);
var prior09Date = new Date(2009,07,01);
var minWage = 8.25;

if (workDate < prior10Date) then
    minWage = 8.00;        // last year amount
   
if (workDate < prior09Date) then
    minWage = 7.75;        // prior year amount

this = minWage;

The error in the last line is:

Error: syntax error near token "minWage" on line 13, column 14

Avatar

Level 4

http://acrobat.com  sign in and you can upload files to that

or you can PM me your e-mail address and I can send you an invite to share a workspace with me and upload your form to that

Avatar

Former Community Member

I've posted the reply in the Designer forum...