DATE MANIPULATION

I just finished helping a customer who wanted to add X number of days to a date entered in a text field
The following was the use case. A form has 2 TextFields Start_Date and End_date
User enters a certain date in the Start_Date text field for example 09/24/08 (MM/DD/YY)
The End_Date should add 90 days to the Start_date and populate the End_Date
The following script would do that
var current = Date2Num(Start_Date.rawValue, “MM/DD/YY”)
var future = current+90
var newDate = Num2Date(future,”MM/DD/YY”)
form1.#subform[0].End_Date.rawValue = newDate

Validating End Date is later than Start Date

var diff = Date2Num(EndingDate.rawValue, “YYYY-MM-DD”) – Date2Num(StartingDate.rawValue, “YYYY-MM-DD”)
if (diff > 0) then
xfa.host.messageBox(“The End date is later than start date”)
else
xfa.host.messageBox(“PLEASE CHECK….The End date is before the start date”)
endif
I have added the pdf here.Please click here to check it out
Date Manipulations

Advertisements

17 responses to “DATE MANIPULATION

  1. Hi Girish,

    These are great examples on your website.

    Can you show me how to manipulate a date so that the field always shows “LAST TUESDAY”‘s date ?

    Thanks !

  2. ok let me get back to you on this
    thanks
    girish

  3. Thanks Girish. I guess the logic would be:
    if today is Tuesday then show today’s date
    if todayTuesday then show last Tuesday’s date

    Appreciate your help !

  4. Oops the blog wiped out some symbols:
    Logic#2 should read
    If today is greater than or less than Tuesday, then show last Tuesday’s date

  5. Try this
    var days = Date2Num(form1.#subform[0].TextField1.rawValue, “MM/DD/YYYY”)
    ar modu = Mod(days,7)
    xfa.host.messageBox(modu)
    if(modu == 2) then
    days = days – 1
    TextField2.rawValue = Num2Date(days,”MM/DD/YYYY”)
    endif
    Jan 1 1900 was a monday, so if TextField1.rawValue is 11/04/2008 then TextField2.rawValue will be set to 11/03/2008

  6. Thanks Girish. I can’t seem to get it to work. I’m using LCD 8.2 and I get an error at ar modu
    Can you please post a working pdf ?

    Thanks very much

  7. make sure you are using formCalc script

  8. Girish, here’s a nice one.

    I need to calculate vacation days between StartingDate and EndingDate…

    Weekends, ie: Sat/Sun occurring between those dates should not be counted.

    How on earth do I do this ?

    Thanks !

  9. Also is it possible to have it check for public holidays entered in an array ?

    So if any dates between StartingDate & EndingDate are Sat/Sun or public holidays it will skip and won’t count them as business days.

  10. Girish-

    I built a form with a DateTime Field for birth date. If defaults to the current date and requires a large effort to scroll back 20 years or more. How can I set the default date for this field to say 1982?

    • Hi
      You can set the default value of the date field by specifying the default value in the “value tab of the object pallete” for the field
      Or your user can enter the date in the format you specify in the “Validation Pattern”
      let me know if this helps
      or you can send me the form,will fix it for you
      thanks
      girish

  11. Hello Grish, I really hope you can help me out. I am using your script above in a form. I have the script below:

    Using LiveCycle Desiger ES

    form1.#subform[0].RequestorDate[1]::exit – (FormCalc, client)
    var current = Date2Num(RequestorDate.rawValue, “M/D/YYYY”)

    PriortyInfo.rawValue = “2-3 Buisness Days”
    var future = current+5;

    PriortyInfo.rawValue = “3-5 Buisness Days”
    var future = current+7;

    PriortyInfo.rawValue = “5-7 Buisness Days”
    var future = current+9
    var newDate = Num2Date(future, “M/D/YYYY”)
    DistributionDueDate.rawValue = newDate

    I am trying to get it so when some one enters in todays date the Distrubtion Due date can be changed based on the Priorty Info they choose.

    So my question is how can I seperate the three chooses so that when they select the “High” 2-3 Buisness Days it only adds 5 days to todays date in a new field, and so on. 5 days because we add 2 additional days for us to look over the request form plus the 2 to 3 days to get there information back to them.

    You have helped me in the past and have done great work, if you could please help me that would be great.

    Thank You

  12. I am wondering if someone could give me assistance with regard to calculating an age in years and months, based on two date fields. I need an age in months and years.

    On my LiveCycyle form I have two date fields ‘dob’ and ‘rdtestdate’.
    I am in Australia so we use dd/mm/yyyy as the format.

    The field designated to display the calculated result — ‘ageyrsmnths’ — is set as a calculated-read only text field.

    What javascript code would I use to calculate the age in years and months, please?

    • var userDate = StartDate.formattedValue;
      //StartDate is the name of the datefield on the form

      //xfa.host.messageBox(“The formattedValue for Start Date is: ” + userDate);

      // Parse the date values from the Date/Time field.
      // The rawValue format is YYYY-MM-DD
      var theYear = userDate.substring(0,4);
      var theMonth = userDate.substring(5,7);
      var theDay = userDate.substring(8);

      // Create a JS date object, useful for date manipulation.
      var dateObj = new Date(theYear,theMonth,theDay);
      var myDay = dateObj.getDate();

      // As a test, display the day of the month.
      //xfa.host.messageBox(“The Day of the Month for Start Date is: ” + myDay);

      //app.alert(“Start Date Milliseconds = ” + dateObj.valueOf());

      //now do the same for end date
      var userDate2 = EndDate.formattedValue;
      //EndDate is the name of the datefield on the form
      //xfa.host.messageBox(“The formattedValue for Start Date is: ” + userDate2);

      // Parse the date values from the Date/Time field.
      // The rawValue format is YYYY-MM-DD
      var theYear2 = userDate2.substring(0,4);
      var theMonth2 = userDate2.substring(5,7);
      var theDay2 = userDate2.substring(8);

      // Create a JS date object, useful for date manipulation.
      var dateObj2 = new Date(theYear2,theMonth2,theDay2);
      var myMonth2 = dateObj2.getMonth();

      // As a test, display the month.

  13. I am new to Life Cycle and am working with check boxes. Is there a way to make the value of the check box equal the caption for that check box. I have about 30 of these on a worksheet and would rather not have to enter in all of the values twice: in caption and value undr binding.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s