Calculating date in ActionScript

I'm figuring a date in a form Flash based on the entry of field values. Basically the user enters a start date and a period in weeks, and I want to calculate and display the end date.

I'm working on ActionScript code to hook to the onChange event of the field.

The closest I got is:
< cfsavecontent variable = "CalcContractExpiryDate" >
ContractExpiryDate.text = ((ContractTerm.text) number * 7 * 24 * 60 * 60 * 1000) + Date (ContractDate.tex t);
< / cfsavecontent >

and then using "onChange = #CalcContractExpiryDate #"
«but the '+' is an addition rather than a calculation, and I have values like ' 604800000Tue 6 Feb 07:57:59 GMT + 1100 2007»

How to do the equivalent of a DateAdd in ActionScript?

Thanks for your reply jedale.

After much research and trying, here's what I had to work. Hope it helps you too.

First of all, if you are wanting to use a European date (dd/mm/yyyy) format in your Flash forms, you must use

to get the calendar to accept and validate the European dates.

So if you want to make the DateAdd and DateDiff functions, go to this link: http://jeff.mxdj.com/dateadd_for_actionscript.htm
Jeff Tapper has created a class that includes DateAdd and DateDiff, but the implementation in the CF is not explained.

Copy the entire class down a bit in his functions in a file named DateFunction.as and save it in the same directory as your CF Flash page. You can now see its functions such as DateFunction.dateDiff and DateFunction.dateAdd.

Its use is:
DateFunction.dateDiff (datePart:String, date1:Date, date2:Date), and
DateFunction.dateAdd (date: Date, datePart:String, num:Number)

The dateDiff function is now expected to pass two dates defined as datefields, but I wanted to spend two text fields containing dates, because the routine was called when the date has had no development and therefore date1.selectedDate and date2.selectedDate were not contain the values that I needed. So I changed the first line of the dateDiff function and added a few lines, as follows:

public static void dateDiff(datePart:String,_date1:String,_date2:String):Number {}
var pieces = date1.split("/");
var day = Number (parts [0]);
var month = Number (parts [1]) - 1;
year var = Number (parts [2]);
var date1 = new Date (year, month, day);
pieces = date2.split("/");
day = Number (parts [0]);
month = Number (parts [1]) - 1;
an = Number (parts [2]);
date2 var = new Date (year, month, day);
Return getDateDiffPartHashMap() [datePart.toLowerCase ()](date1,date2);
}

Then I was able to use:
var vDaysLeft = number (DateFunction.dateDiff ("d", _root. Date1.text, _root. Date2.text));

Tags: ColdFusion

Similar Questions

  • Create only average column calculated date field

    Hello

    I am creating a single field at the bottom of a report to calculate the average number of days, based on the calculation of the 2 other fields date similar to this example below. I understand that I need a subquery, but can't seem to build the SQL correctly. In the table below is an example of what I'm trying to build, AVERAGE = 7.5.  The SQL code that I use to create the cycle time field that I'm trying to average is "ROUND (GLOGOWNER.» THE INVOICE. DATE_RECEIVED - GLOGOWNER. SHIPMENT_STOP. ACTUAL_DEPARTURE, 0) AS "" DURATION in days".

    SELECT ROUND (GLOGOWNER. THE INVOICE. DATE_RECEIVED - GLOGOWNER. SHIPMENT_STOP. ACTUAL_DEPARTURE, 0) IN the 'Cycle time in days.

    OF GLOGOWNER. SENDING

    JOIN INTERNAL GLOGOWNER. INVOICE_SHIPMENT

    ON GLOGOWNER. DELIVERY. SHIPMENT_GID = GLOGOWNER. INVOICE_SHIPMENT. SHIPMENT_GID

    JOIN INTERNAL GLOGOWNER. INVOICE

    ON GLOGOWNER. THE INVOICE. INVOICE_GID = GLOGOWNER. INVOICE_SHIPMENT. INVOICE_GID

    JOIN INTERNAL GLOGOWNER. SHIPMENT_STOP

    ON GLOGOWNER. DELIVERY. SHIPMENT_GID = GLOGOWNER. SHIPMENT_STOP. SHIPMENT_GID

    JOIN INTERNAL GLOGOWNER. SHIPMENT_STOP SHIPMENT_STOP1

    ON GLOGOWNER. DELIVERY. SHIPMENT_GID = SHIPMENT_STOP1. SHIPMENT_GID

    WHERE GLOGOWNER. DELIVERY. DOMAINNAME LIKE "UPS/CP/%B".

    AND GLOGOWNER. SHIPMENT_STOP. STOP_NUM = 1

    AND SHIPMENT_STOP1. STOP_NUM > 1

    ACTUAL_DEPARTUREDATE_RECEIVEDCycle in days time
    01/07/201414/07/201413
    04/07/201406/07/20142
    01/08/201411/08/201410
    02/08/201407/08/20145
    AVERAGE7.5

    Thank you very much for the help.

    Kind regards

    -Adam

    Add the "CUMULATIVE" at the end of the group by, and NOT in the select section

    SELECT Glogowner.Shipment.Domain_Name AS field

    , SUBSTR (Glogowner.Shipment.Servprov_Gid,-4) AS Scac

    , Glogowner.Shipment.Transport_Mode_Gid AS 'Mode '.

    CASE

    WHEN Ir.Insert_Date<= i.insert_date="" then="">

    WHEN I.Invoice_Source = 'I' and THEN 'EDI '.

    WHEN I.Invoice_Source = 'G' THEN 'debit '.

    WHEN I.Invoice_Source = am' THEN 'manual '.

    END

    AS a Source

    , Glogowner.Shipment.Shipment_Xid AS 'Expedition ID ".

    , Glogowner.Shipment_Stop.Actual_Departure AS "Delivery Date".

    , Shipment_Stop1.Actual_Arrival AS "Delivery Date".

    , I.Invoice_Number AS "invoice number".

    , I.Invoice_Date AS "Date of the invoice.

    , The LEAST (I.Insert_Date, Ir.Insert_Date) AS 'receipt of Invoice Date.

    , TOWER (I.Date_Received - Glogowner.Shipment_Stop.Actual_Departure, 0)

    AS of the time of Cycle "within days".

    INVOICE I have

    INNER JOIN Invoice_Refnum Ir ON I.Invoice_Gid = Ir.Invoice_Gid

    JOIN INTERNAL Glogowner.Invoice_Shipment

    ON I.Invoice_Gid = Glogowner.Invoice_Shipment.Invoice_Gid

    JOIN INTERNAL Glogowner.Shipment

    ON Glogowner.Shipment.Shipment_Gid =

    Glogowner.Invoice_Shipment.Shipment_Gid

    JOIN INTERNAL Glogowner.Shipment_Stop

    ON Glogowner.Shipment.Shipment_Gid =

    Glogowner.Shipment_Stop.Shipment_Gid

    INNER JOIN Glogowner.Shipment_Stop Shipment_Stop1

    ON Glogowner.Shipment.Shipment_Gid = Shipment_Stop1.Shipment_Gid

    WHERE Glogowner.Shipment_Stop.Actual_Departure IS NOT NULL

    AND Shipment_Stop1.Actual_Arrival IS NOT NULL

    AND Ir.Invoice_Refnum_Value = 'ACS '.

    AND Ir.Invoice_Refnum_Qual_Gid = 'SOURCE '.

    AND I.Invoice_Type = 'I '.

    AND Glogowner.Shipment_Stop.Stop_Num = 1

    AND Shipment_Stop1.Stop_Num > 1

    GROUP BY ROLLUP (AVG (ROUND (I.Date_Received - Glogowner.Shipment_Stop.Actual_Departure, 0)))

    ORDER BY I.Invoice_Gid;

  • Calculation date returns a decimal number. Is this good?

    Hi people,

    Forgive me, because I'm a newbie.

    I'm doing the calculation simple date

    Select SYSDATE - TO_DATE (December 10, 1986 "," MON/DD/YYYY "") double

    and the result is

    '8147.62126 '.

    The result is not intended to be a date? Since I'm subtracting a date from a date?

    Thanks :)

    You can mark yet replied if you question is answered.

  • Acrobat calculated Date JavaScript

    Hi, I was wondering if anyone can help me with this.

    I have a form that all people to travel. Some things must be submitted at the latest of the specific days before their trip.

    Beginning of the form has travel Q.1 date: mm/dd/yy

    Based on the date of travel, there are some delays to complete a few items.

    For example

    Q2. submit form 0900 not later than [mm/dd/yy]-> here he spits a date who is info date above travel less, say, 60 days.

    So on and so forth. I would be able to apply the rule to several questions, but would be grateful if anyone can help with the appropriate insert to this script?

    Thanks a bunch!

    function adddays (xDate, xAddDays) {}
    var date1 = new Date (xDate)
    var ndate1 = Date.parse (date1);
    var ndate2 = ndate1 + 86400000 * xAddDays
    date2 var = new Date (ndate2)
    Return util.printd ("mm/dd/yy", date2)
    }

    var Q1date = this.getField("Q1").value
    var daystoadd = 60
    this.getField("Q2").value = adddays (Q1date, daystoadd)

  • Difference of field calculation date

    Hi all

    I am new to Adobe and Java script so apologies if this has already been answered elsewhere - I was not able to find it if it has.

    I want to calculate the difference between two date fields in hours and minutes on a form.

    I have two fields, the Date format (dd/mm/yyyy hh: mm), a start and end date and I want the difference between them at the time in the format hh: mm.

    Can someone help me with the script for this? What I have so far is:

    var strStart = this.getField("StartTime").value;

    var strEnd = this.getField("EndTime").value;

    if(strStart.Length || strEnd.Length)

    {

    var dateStart = util.scand ("mm/dd/yyyy hh: mm", strStart);

    var dateEnd = util.scand ("mm/dd/yyyy hh: mm", strEnd);

    diff var = dateEnd.getTime () - dateStart.getTime ();

    One day = (24 hours) x (60 minutes/hour) x

    (60 seconds/minute) x (1000 milliseconds per second)

    var oneMin = 60 * 60 * 1000;

    var minutes = Math.floor (diff/oneMin);

    Event.Value = util.printd("HH:MM",mins);

    }

    But it does not work...

    Mary

    Got it - Thanks for your help - really appreciate it.

  • need help for calculation date

    I need help with this:

    I added successfully a document level script to add the date printed in my document

    this.getField("DatePrinted").value = util.printd ("mm/dd/yy", new Date());

    I now need to fill in a field named "Date" with a date that is 14 days after the date of DatePrinted.

    and I'm lost.

    Can anyone help?

    Get the current date/time

    var d = new Date();

    Add 14 days

    d.setDate (d.getDate () + 14);

    Set a field value

    getField("Deadline").value = util.printd ("mm/dd/yy", d);

    That last part may need to be changed depending on where you place the script. If it's the same script at the document level, the whole thing can be:

    Get the current date/time

    var d = new Date();

    Set a field value

    getField("DatePrinted").value = util.printd ("mm/dd/yy", d);

    Add 14 days

    d.setDate (d.getDate () + 14);

    Set another value of field

    getField("Deadline").value = util.printd ("mm/dd/yy", d);

  • Time sheet calculation date

    I did some research on this for hours and I just can't understand, so I hope someone can help me here...

    I have a timesheet form where I want the user to click on the first box that I put up as a date field so the little open pop calendar. Once they choose the date in this field (I named dtf [0]) I would like to the rest of the fields to be filled automatically with dates for the rest of the week. I prefer the format to show only the month and the day - no year is needed.

    Example: the user chooses August 15, so the first field will display 8/15 and the rest of the week will be filled with 8/16, 8/17, 8/18 etc.

    Go to a previous thread wrote here last year, I found this code and twisted to apply to my domain names:

    Form1. .DTF #subform [0] [0]: output - (FormCalc, client)

    XFA. Form.Form1. #SubForm. Table2.Row1.DTF [1] = Num2Date ((Date2Num (xfa.form.form1. #subform.))) "Table2.row1.DTF [0]." (FormattedValue, "M/D") + 1), "M/d"); "
    XFA. Form.Form1. #SubForm. Table2.Row1.DTF [2] = Num2Date ((Date2Num (xfa.form.form1. #subform.))) "Table2.row1.DTF [0]." (FormattedValue, "M/D") + 2), "M/d"); "
    XFA. Form.Form1. #SubForm. Table2.Row1.DTF [3] = Num2Date ((Date2Num (xfa.form.form1. #subform.))) "Table2.row1.DTF [0]." (FormattedValue, "M/D") + 3), "M/d"); "
    XFA. Form.Form1. #SubForm. Table2.Row1.DTF [4] = Num2Date ((Date2Num (xfa.form.form1. #subform.))) "Table2.row1.DTF [0]." (FormattedValue, "M/D") + 4), "M/d"); "
    XFA. Form.Form1. #SubForm. Table2.Row1.DTF [5] = Num2Date ((Date2Num (xfa.form.form1. #subform.))) "Table2.row1.DTF [0]." (FormattedValue, "M/D") + 5), "M/d"); "
    XFA. Form.Form1. #SubForm. Table2.Row1.DTF [6] = Num2Date ((Date2Num (xfa.form.form1. #subform.))) "Table2.row1.DTF [0]." (FormattedValue, "M/D") + 6), "M/d"); "

    But I'm running into the same problem as the person who wrote the other thread has made... After my field date fields are populated, but 1/1, 1/2, 1/3 etc.!

    Moreover, the first field (dtf [0]) is a date/time field, while the other days of the week are only plain text areas. (Wasn't sure if they should all be date/time fields, perhaps?)

    What I'm doing wrong here? I don't know anything about JavaScript or FormCalc (clearly)! Thanks for any help you can provide...

    Check the attached samples...

    I write the script in FormCalc event and out of control...

    Also check the view model.

    https://Acrobat.com/#d=xH1H6-8fmYRxxQn2sZuIMA

    Thank you

    Srini

  • The years between 2 fields calculation date

    I have am trying to create a form in LiveCycle Designer 7 missing persons report.  I want to fill in a text field with the number of years between two dates entered in date/time fields; specifically using the DOB of a missing person and the date they have been seen to calculate their age during the last time.

    Any help would be greatly appreciated.

    Thank you

    Drew

    FormCalc has a "A Value()" function that returns "true" only when the field has been updated, you can add an if statement uses the function 'Value() a' for both fields and return a true result only when both fields have given.

  • How do a unchanging calculated date after save / submit

    Hi all

    I've created a form that records of service calls. After filling in the name of the person concerned, a date and time is generated. The problem is that the next time I open this file, the date defaults to the current. I would like to know how to validate the date when the form is saved, so it does not automatically update next time I open the form. Any help is greatly appreciated.

    Locking does that stop the user from editing the field... .emissions can touch them again. Yes, you can send me the form... include a description of the problem as the forum and electronic mail are not attached together and I get easily confused as to what is going on with anything. You can send it to [email protected]

    Paul

  • How can I save machine vision data calculated?

    Hello everyone,

    I developed a machine vision vbai file to detect the edge of a droplet and calculate the radius of the drop. However, I would like to save the data of droplets of RADIUS in a file so that I can follow the distributions of droplets at the time RADIUS and see it in excel for example.

    However, in the range of functions of industrial vision I see not all save data option and so I transferred the code in a labview VI hoping to get more options. When I opened this VI, I can't really find out where my calculated data are, and I can't also manage store data anyway.

    I'll post the Labview VI and VBAI files and hope someone can tell me how I can save the droplet radius size because I'm kinda a noob in programming Labview.

    Thanks in advance Schoonen Jan-Willem

    Hi René,.

    It worked, thank you very much!

  • calculation of the average value of the sorted data and polar route drawing

    Hello

    I did a VI that calculates the average value of the wind rotor/speed-ratio in the sections of 30 degrees (wind direction). He also called the polar plot of calculated data. Everything works, but I would like to make more detailed calculations and drawings, by increasing the resolution to 1 degree, or...

    Problem is VI, I did, is not easy on a large scale. At the moment, I have 12 parallel structures of switch-box to calculate the average value and build the array function to collect data calculated for Polar plot to draw the image in real time. I know it's probably the worst way to do it, but since I have done a few things with LV, it was the only way I managed to do what I wanted.

    Now, if I continue in same way to reach my goal, I have to create 360 Parallels switch-case structures... that are crazy.

    Something like the calculation of the average of the table or matrix (zero/empty values should not be calculated on average) inside the loop or similar way would probably be the best solution.

    So, polar plot drawing is not a problem, but creating a reasonalbe average metering system is. Any ideas?

    I would also like to rotare northward to the top (0 deg), and degrees of increase in a clockwise direction on polar ground dial plate (as on the compass).

    VI on the attachment. (simplified version of the complete system)

    I have signals:

    -Wind speed

    -wind direction

    -Rotor speed

    I want to:

    -calculate the average value of the speed of the wind / rotor - ratio in sections (5 degrees, 1 degree)

    -Draw a polar path of the wind rotor/speed-ratio of averages in propotion of wind direction

    I'm using LabView 2009

    Thank you very much.

    It is closer to what you're looking for?

  • How do I load the data calculated in HFM

    Hi gurus

    1. how to load the data calculated in HFM?

    I extracted the calculated data and when I tried to load the data calculated in HFM is partially responsible, showing the errors you can not load data for parent members of the account, Custom personalized 1 4...
    Then I ran the consolidation to get the values of the parent company.
    Is there an alternative way to load the data calculated in HFM?

    Concerning
    Hubin

    Hi Hubin,

    Calculated data cannot be loaded in HFM manually, these accounts with calculated field data should be generated through the logic of the computation.

    And parent members also don't take the data they are parents for the sum of some basic level accounts.

    So just load the data for basic level accounts and make sure they are consolidated accounts of field, that there was no error and calculated accounts data automatically generates through the logic written in the Rules file.

    And after loading data just run the consolidation and sink also rules file in both cases to the work of the logic of the computation.

    Kind regards
    Srikanth

  • Calculation of current date or the previous months

    Script gurus of wishes!

    I would like to ask help on calculating Date.

    Here's my current scenario:

    The user enters a date mm/dd/yyyy ("DateField")

    Power here ask the 'DateField' to calculate these items:

    Less "DateField" 12 months = ("12MonthsAgoDateField") / mm/yyyy

    'DateField' 18 months = ("18MonthsAgoDateField") / mm/yyyy

    'DateField' less than 36 months = ("36MonthsAgoDateField") / mm/yyyy

    and so on...

    I read some posts Date of calculation, but could barely find anything that fit this scenario.

    Freely, I confess that my ability to script is very minor.

    I would appreciate help in this script.

    Thank you!

    If you really want to go into the details (or not the time to do)

    Here is the simple solution to your problem.

    I wrote a small function (a few lines)

    Put this in the document level javascript

    Function level javascript document-

    function getPastDate (textFieldName, month) {}

    var util.printd = cDate ("dd/mm/yyyy", new Date (this.getField ("textFieldName") .value));

    sDate var = util.scand ("mm/dd/yyyy", cDate);

    If (sDate == null) {}

    App.Alert ("Please enter a valid date in the form \"mm/dd/yyyy\". »)

    } else {}

    update var = new Date (sDate.getFullYear (), (sDate.getMonth () + months), sDate.getDate ());

    Return util.printd("mm/yyyy",pDate);

    }

    }

    Now suppose that we have a text box name "Text1" including the date in the format "mm/dd/yyyy".

    1st parameter is for the name text box (seen the date that you want to process)

    2nd parameter is the number of months (to subtract pass a negative value)

    If you want to get the result in another area of text "Text2" write the following code in the event to calculate Text2

    Event.Value = getPastDate ("Text1",-12);

    This removes 12 month value "Text1".

    Hope this will help

  • Application date HTTP header can be set via ActionScript.

    Hi all

    I'm moving urlrequest liaison with 'Date', 'Licence' to amazon s3 to flex 4.5 web application. However, it is unable to connect and get the error as,

    Error #2096: Could not set the request header HTTP Date via ActionScript.

    So, please tell me what I need to use or that flash player supports to add "Date" at the request of the header.

    Sory for the late reply. I used presigned url to download files from s3.

  • Custom calculation script (date roll forward)

    I am trying to add 6 days to a date that is in a field defined by the user named PeriodBegin

    The new calculated date must b e: PeriodBegin + 6 days and must be displayed in a new field called PeriodEnd

    I tried to use some code I found on the web but can't make it work.    Help!

    See this: http://forums.adobe.com/thread/836872

Maybe you are looking for

  • With Satellite C660D-181 performance issues

    Hello Hoping someone can help me.I've had the above machine now for about 2 months and it is so incredibly slow. It has 6 GB of ram and a processor double heart and was bought to replace a child of 4 years another laptop. Constantly, it crashes when

  • Frustration of the app

    I have 3 apple TV. I find it incredibly frustrating that I have to go through the laborious task of having to go to a computer and enter the access codes for each individual application. Once this is done, I have again this ridiculous task for each A

  • I keep getting "the trust relationship between this workstation and the primary domain failed" error windows 2008R2

    Hi all I appreciate your help. And I hope that this issue has been addressed previously, although I couldn't find any solution there. I manage a domain windows 2008 with 3 domain controllers. Recently my workstations continue to fall out of the field

  • -What this means and how can I solve this problem?

    My computer has recently been fixed and now I can't send emails via Outlook Express.This is the message I get when I try to send an e-mail with an attachment: failed to connect to the server. Account: ' * address email is removed from the privacy *',

  • Question Smartband and lifelog

    Smartband is supposed to connect your driving? If Yes, at least the one I have does not transmit something on my driving to lifelog... I read somewhere that its supposed to do... Pls help...