IF Statement and Increasing the hour by 1

Hello,

I am trying to set my ‘Email Time’ value to ‘08 AM’ if the time is between ‘05 PM’ and ‘07 AM’. And if the time is between ‘08 AM’ and ‘04 PM’ just set the ‘Email Time’ value to the current hour plus 1 hour.

Here is what I have currently set up

emailtime

The email type gets set to ‘08 AM’ no matter what the hour is, I am unsure why this occurs.

As for increasing the hour by 1, I have not found any way of doing this so any help would be appreciated.

Cheers,
Brendan

Hi @BrendanJ

This is something very tricky and I believe it might become even more complex if you attempt to apply the formula. My suggestion is to employ a Data store, with time as the key value, for this purpose.

For further help, please connect to us

MSquare Support
Visit us here
Youtube Channel

@Msquare_Automation A data store is an overkill for a simple operation like this and is terrible advice. Are you simply replying just so you can spam your links? I noticed that you have been doing that in every post you made. According to the community guidelines “promotional efforts is forbidden”, and in the Ultimate Topic, “avoid spamming every conversation with self-promotional comments”


Hello @BrendanJ, welcome to the Make community! This is actually quite simple, you just need to use the date formats in a way where you can perform math on them!

Let’s break this down into steps

  1. Get the current hour, from 0-23 (see date formats)

    formatDate(now; H)
    
  2. You want to do something if hour of day is 8 to 16 inclusive, and something else otherwise:

    if(formatDate(now; H) >= 8 & formatDate(now; H) <= 16; ; )
    
  3. If between 8 - 16, you want (current hour plus 1 hour). You need to use parseNumber before you perform math operations:

    setHour(now; 1 + parseNumber(formatDate(now; H)))
    
  4. Output previous step in your required format (hh A):

    formatDate(setHour(now; 1 + parseNumber(formatDate(now; H))); hh A)
    
  5. Otherwise, you just want the text “08 AM”

    08 AM
    
  6. Final variable after combining all the steps above:

    if(
      formatDate(now; H) >= 8 & formatDate(now; H) <= 16; 
      formatDate(setHour(now; 1 + parseNumber(formatDate(now; H))); hh A); 
      08 AM
    )
    

Here’s how it should look like

Screenshot_2023-09-04_110950

Download blueprint

blueprint.json (4.5 KB)

3 Likes

Thank you so much, greatly appreciated!

Sorry to bother you again, but I would also like to do similar with my ‘day’ variable.

image

I have made it so it sets the day to ‘Monday’ if it is Saturday or Sunday. And sets it to the current day if it is not. However, if the Email Time is set to 08 AM, I want it to set the day to the next day. And if it is Friday, Saturday or Sunday set the day to Monday.

Hopefully this makes sense.

Thanks so much,
Brendan