• Resolved pexel

    (@pexel)


    Hello,
    I am writing a date calculation function. My actions are briefly;

    I am getting date information from user (datefield)
    I also have 4 number fieldname fields.
    fieldname19 : Represents the year.
    fieldname20 : Represents the month.
    fieldname21 : Represents the week.
    fieldname22 : Represents the day.

    I am trying to calculate by taking this information from the user.

    For example, the user entered a value of 2 in fieldname19 (i.e. 2 Years)

    How can we add on the first selected (datefield) by converting both the year?

    We think your support will be great help in this matter.
    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @pexel

    Thank you very much for using our plugin.

    If the feldname1 is a date field, and the number fields fieldname19 has a year value, fieldname20 months, fieldname21 weeks, and fieldname22 days, and you want to sum them to the date field and get the result in date format. You can insert a calculated field in the form and enter the following equation:

    (function(){
    var result = fieldname1;
    
    result = DATETIMESUM(result, 'dd/mm/yyyy', fieldname19, 'y');
    result = DATETIMESUM(result, 'dd/mm/yyyy', fieldname20, 'm');
    result = DATETIMESUM(result, 'dd/mm/yyyy', fieldname21*7+fieldname22, 'd');
    
    return GETDATETIMESTRING(result, 'dd/mm/yyyy');
    })()

    Best regards.

    Thread Starter pexel

    (@pexel)

    What if we want to extract it the same way?
    You’re great at support, by the way.

    Plugin Author codepeople

    (@codepeople)

    Hello @pexel

    If you want to extract date components and assign them the number fields, the equation in the calculated field would be:

    (function(){
    getField(fieldname19|n).setVal(YEAR(fieldname1));
    getField(fieldname20|n).setVal(MONTH(fieldname1));
    getField(fieldname21|n).setVal(WEEKNUM(fieldname1));
    getField(fieldname22|n).setVal(DAY(fieldname1));
    })()

    Note the use of |n modifier in fieldname19|n, fieldname20|n, fieldname21|n, and fieldname22|n. The plugin replaces the fields’ names with their values before evaluating the equations. The |n modifier tells the plugin you are referring to the fields’ names directly instead of their values.

    Best regards.

    Thread Starter pexel

    (@pexel)

    then I’m writing to wrap it up, if there is a wrong part, I would appreciate it if you could help.
    When adding a date function;

    (function(){
    var sonucsure = fieldname17;
    
    sonucsure = DATETIMESUM(sonucsure, 'dd/mm/yyyy', fieldname19, 'y');
    sonucsure = DATETIMESUM(sonucsure, 'dd/mm/yyyy', fieldname20, 'm');
    sonucsure = DATETIMESUM(sonucsure, 'dd/mm/yyyy', fieldname21*7+fieldname22, 'd');
    jQuery('#calculation-sonucsure').html(sonucsure);
    return GETDATETIMESTRING(sonucsure, 'dd/mm/yyyy');
    })()

    I couldn’t print the result “calculation-sonucsure”

    In fact, I’m currently thinking about how to do the subtraction as above and vice versa. I failed ??

    Plugin Author codepeople

    (@codepeople)

    Hello @pexel

    In the line of code:

    jQuery('#calculation-sonucsure').html(sonucsure);

    sonucsure is an object, the GETDATETIMESTRING operation transform it into a text with date format. So, the option would be transform it before displaying it on the page and return the equation:

    (function(){
    var sonucsure = fieldname17;
    
    sonucsure = DATETIMESUM(sonucsure, 'dd/mm/yyyy', fieldname19, 'y');
    sonucsure = DATETIMESUM(sonucsure, 'dd/mm/yyyy', fieldname20, 'm');
    sonucsure = DATETIMESUM(sonucsure, 'dd/mm/yyyy', fieldname21*7+fieldname22, 'd');
    
    sonucsure = GETDATETIMESTRING(sonucsure, 'dd/mm/yyyy');
    jQuery('#calculation-sonucsure').html(sonucsure);
    return sonucsure;
    })()

    For additional questions, please, indicate the URL to the page that contains the form to check your equation in action.

    Best regards.

    Thread Starter pexel

    (@pexel)

    Thanks, I realized my mistake and got the result.
    A very impressive plugin.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Number and Date Relationship’ is closed to new replies.