• Resolved holyman842

    (@holyman842)


    Hi,

    I plan on using if/else conditions with date.

    The formula is quite simple. If the user selects a particular date, the result will be determined based on the date.

    Say for example if the user selects 01.03.15 then the result will be Meeting time 12 pm (We want a similar output, Meeting time vary according to date)

    This is the formula I am using. Please let me know what should be used instead.

    IF(fieldname6==”03/01/05″){
    return “Meeting at 12 pm”
    }
    else IF(fieldname6==”04/01/05″){
    return “No meetings sorry”
    }
    else IF …
    .
    .
    .
    else
    {
    return “Error”
    }

    FYI, we are using DD/MM/YY format.

    Please let us know if this is possible.

    Kind Regards,
    Arindom

    https://www.ads-software.com/plugins/calculated-fields-form/

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

    (@codepeople)

    Hi,

    Your equation has some errors:

    First, you should decide to between use the conditional statement if/else, or the operation “IF”, implemented in the plugin. Javascript is a case sensitive language.

    Using the conditional statement, you should define the equation inside a function, like follow:

    (function(){

    var d = CDATE(fieldname6);
    if(d == “03/01/05”){
    return “Meeting at 12 pm”;
    }
    else if(d == “04/01/05”){
    return “No meetings sorry”;
    }

    return “Error”;

    })()

    You should use the CDATE operation to convert the selected date, in a string representation, because you are comparing with a string representation of a date.

    Your equation is returning a text and not a numeric value. The calculated fields are implemented to display the result of a mathematical equation, so, you should modify the plugin’s code, like is explained in the following question of the FAQ (https://www.ads-software.com/plugins/calculated-fields-form/faq/):

    Q: How can be displayed texts in the calculated fields?

    Now, I’ll display the same equation, but using the “IF” operation. The format of this operation is:

    IF(condition, value if condition is true, value if condition is false )

    So, the equation would be:

    IF(CDATE(fieldname6) == “03/01/05”, “Meeting at 12 pm”, IF(CDATE(fieldname6) == “04/01/05”, “No meetings sorry”, “Error”))

    If you need additional assistance with the formula’s development, please, contact me through our support page, to offer you our custom coding services.

    Best regards.

    Thread Starter holyman842

    (@holyman842)

    Hi,

    Thank you for the very very quick reply. I was hoping that there would be a way to read an external code file or something similar.

    I have to type in the details of the entire year 2015 (Lots of work). So as you can understand, its going to be very hard to code everything into that small coding window. I am talking about 365 conditional statements.

    So is there any way to do that or should I code everything into that small coding area. I have the developer version of the plug in if that helps.

    Thanks again for the really good support,
    Arindom

    Plugin Author codepeople

    (@codepeople)

    Hi,

    The solution will depend of the data, if the data are stored in a external data source, maybe a database, you might use the developer version of the plugin, for selecting only the available dates in your database, but as I said, the solution will depend of the data.

    If you need additional support with your equation, don’t hesitate in contact me through the support page, and I will offer you a custom coding service:

    https://wordpress.dwbooster.com/support

    Best regards.

    Thread Starter holyman842

    (@holyman842)

    Hi,

    Thank you very much for the support. I have finally found an easier way to crack the code. I had no idea that the form also supports logical operators like AND and OR.

    The code I used is

    if(d == "01/01/2015" || d == "02/01/2015

    I am really enjoying this plugin. Its very powerful. Please feel free to visit the form test page here(named Absolute Booking)

    Thank you,
    Arindom

    Plugin Author codepeople

    (@codepeople)

    Hi,

    Yes, the use of logical operators is a valid solution.

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Conditional statements with date’ is closed to new replies.