• Resolved klingbeil

    (@klingbeil)


    Hi;

    fieldname13 = User selected date

    fieldname22 = Estimated Date of Birth

    it states. I wrote a criterion, if 2 criteria date is greater and less, it adds an expression to the result.

    Currently the benchmark is working, but there is a problem. For example, I selected a date before March 5, 2023, it prints the correct result. However, when we select March 8, 2023 without refreshing the page, it takes the post-criterion criterion into account. Is it possible to put a reset in between?
    Thanks.

    Sample : I chose March 05, 2023. criteria5 += ‘he gave birth first’; writes a warning.
    Without refreshing the page;

    I chose 08 March 2023. criteria5 += ‘he gave birth first’; should write a warning
    criteria5 += ‘she will give birth later.’; writes a warning.

    (function(){
    
      var o = DATEDIFF(fieldname22, fieldname19, 'dd-mm-yyyy', 'd');
      var kriter5 = o['days'] + ' gün';
    
      if (fieldname13 < fieldname19) {
        kriter5 += ' ?nce do?um yapt?.';
      } else if (fieldname13 > fieldname19) {
        kriter5 += ' sonra do?um yapacak.';
      }
    
      jQuery('#calculation-kriter5').html(kriter5);
      jQuery('.kriter5-aciklama').html('Do?uma Kalan Süre : ');
      jQuery('.kriter5-sonuc').html(kriter5);
    
      return kriter5;
    })();
    • This topic was modified 1 year, 2 months ago by klingbeil.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil

    Sorry, but I don’t understand your description. Also, it is not clear who fieldname19 is (Please include the link to the page containing the form to check its structure in detail).

    Note your equation can be improved. There are some unnecessary instructions:

    (function(){
    
      var kriter5 = DATEDIFF(fieldname22, fieldname19, 'dd-mm-yyyy', 'd')['days'] + ' gün';
    
      if (fieldname13 < fieldname19) {
        kriter5 += ' ?nce do?um yapt?.';
      } else {
        kriter5 += ' sonra do?um yapacak.';
      }
    
      jQuery('#calculation-kriter5').html(kriter5);
      jQuery('.kriter5-aciklama').html('Do?uma Kalan Süre : ');
      jQuery('.kriter5-sonuc').html(kriter5);
    
      return kriter5;
    })();

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    Now I am writing a pregnancy calculation form for cats.
    fieldname13 Field = User selected date
    fieldname22 Field= Estimated Date of Birth (Calculation result)

    Hesaplama

      if (fieldname13 < fieldname19) {
        kriter5 += ' ?nce do?um yapt?.';
      } else {
        kriter5 += ' sonra do?um yapacak.';
      }

    if (fieldname13 < fieldname19) {

    If there is a date before, kriter5 += ' ?nce do?um yapt?.';

    If a later date results, kriter5 += ' sonra do?um yapacak.'; statement is included.

    Up to this point, everything works fine.

    If the previous date appears kriter5 += ' ?nce do?um yapt?.'; writes the result.

    My main question is calculating the before and after result.
    But without refreshing the page;
    For example, I wrote a date before March 05, it gives the correct result, I write the date before again, but a date after March 05 is March 08 (actually, it is the past date again)
    kriter5 += ' sonra do?um yapacak.'; writes the result.

    Thanks

    Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil

    There is an issue in your equation. The fieldname13 and fieldname19 on your form are calculated fields whose results are texts with date format. If you compare two texts, the browser does it alphabetically.

    For example, if the fieldname3 value is “01/10/2024” and the fieldname19 value is “22/05/2023”, the comparison fieldname3 < fieldname19 returns true. As I indicated above, since their values are texts, the comparison is alphabetical.

    So, the correct would be to transform them into date objects before comparing them:

    if (DATEOBJ(fieldname13, 'dd/mm/yyyy') < DATEOBJ(fieldname19, 'dd/mm/yyyy')) {
        kriter5 += ' ?nce do?um yapt?.';
     } else {
        kriter5 += ' sonra do?um yapacak.';
     }

    Also, remember you have disabled the dynamic evaluation of the equations, and the user must press the calculate button to re-evaluate the equations.

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    yes, now I understand the problem, thanks to you, thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Date criteria problem’ is closed to new replies.