IF Statement and Increasing the hour by 1

@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