How to create a code "when the date field is equal to or less than 5 days ahead"?

@iurirb has asked:

how to create a code “when the date field is equal to or less than 5 days ahead”?

I have an automation in beckend that every day at a specific hour it fetches information within a tab, depending on the date of a field, it changes the status. So I would like to add this logic

@fernando.nakandakari can u give Iuri some tips?

Hey @iurirb

There are two ways you can solve this, both of them involving changing the ‘where’ filter a bit:

  1. You could add a simple LESS THAN OR EQUAL TO.

It would look something like this:

$searchCO = Jestor.loadData('jornada',['where'=>['checkin_2 <=' => date('Y-m-d', time()+(120*3600))]]);

Notice all that is different is the “<=” condition right next to the field name (checkin_2). This is the easiest way to go, but will also fetch results in the past: that is, you’ll also get records where checkin_2 is yesterday, or a month ago. If that’s not desirable, you can go with the solution below.

  1. Change the filter structure.

You can also write filters in a more complex manner by making it all a single string. Like so:

$today = date('Y-m-d');
$fivedays = date('Y-m-d', time()+(120*3600))

$searchCO = Jestor.loadData('jornada',['where'=>["checkin_2 >= '$today' AND checkin_2 <= '$fivedays'"]]);

This filter will only bring up records that are greater than or equal to today AND less than or equal to five days from now.

Hope that helps :slight_smile:

1 Like

@fernando.nakandakari Acredito que tenha dado certo! Teria como forçar o gatilho pra eu ver se funcionou?

Hey, @iurirb

If it’s a backend function, the best way to test it would be:

  1. Go to the low-code area.
  2. Click on Webhooks.
  3. Create an active webhook for that function.
  4. Copy the URL, paste it in the address bar of your browser (such as Chrome or Firefox), then press enter.