Skip to content

Working with Dates and Times in VisualMakerΒΆ

VisualMaker offers powerful tools for handling dates and times. These capabilities allow you to format dates, perform time calculations, and customize the behavior of your bots based on time.


Date and Time formatΒΆ

In VisualMaker, dates and times are represented in the format:

DD-MM-YYYY HH:MM:SS
  • DD: Day of the month (01-31).
  • MM: Month of the year (01-12).
  • YYYY: Year (4 digits).
  • HH: Hour in 24-hour format (00-23).
  • MM: Minutes (00-59).
  • SS: Seconds (00-59).

For example:

19-01-2025 12:01:55

Date variablesΒΆ

Date type variables can store dates to be reused in your bot.

Creating a date variableΒΆ

  1. First, create the variable by going to:

    πŸ”‘ Manage β†’ πŸ—ƒ Variables β†’ πŸ’  Create variable πŸ’ 

  2. In ➑️ Data type:, select date πŸ“….

  3. Enter the variable name.

Using date variablesΒΆ

Date variables allow you to store dates for validation purposes. For example, if you want a button to be pressed only once every 15 minutes, a date variable will make this possible. We will see examples of this later.

Displaying a date variableΒΆ

Once the variable is created and a date is saved inside it (we'll see how later), you can display its content in messages and actions as follows:

{my_variable}

Assuming you created a variable called my_variable, this will display something like:

19-01-2025 14:05:30

What are variables?

For more information about variables, click here.


Dates in UTCΒΆ

It is recommended to work with dates and times in UTC (Coordinated Universal Time). You can use the date_now() function to get the current date and time without local adjustments. This is the function you will use most when working with dates in VisualMaker.


Displaying Dates and Times in messagesΒΆ

You can insert dates and times in messages using functions within expressions:

Basic example:

The current date and time is: {date_now()}

This will display something like:

The current date and time is: 20-01-2025 15:45:12

Expressions

Functions are represented using expressions, so they must be enclosed in curly braces { }.


Functions for working with Dates and TimesΒΆ

1. date_now()ΒΆ

Returns the current date and time in UTC.

{date_now()} βž” "20-01-2025 15:48:00"

2. date_now_tz()ΒΆ

Returns the current date and time according to the configured time zone.

{date_now_tz()} βž” "20-01-2025 13:48:00"

3. apply_tz()ΒΆ

Applies the bot's time zone to a given date and time.

{apply_tz("01-03-2024 00:07:48")} βž” "01-03-2024 02:07:48"

4. date_format()ΒΆ

Formats a date and time to a specific format.

{date_format("20-01-2025 15:30:00", "%d/%m/%Y")} βž” "20/01/2025"

5. time_passed()ΒΆ

Calculates the time elapsed from a given date until now.

{time_passed("19-01-2025 15:30:00", "hours")} βž” "24"

6. time_left()ΒΆ

Calculates the time remaining until a given date.

{time_left("21-01-2025 15:30:00", "days")} βž” "1"

7. time_add()ΒΆ

Adds a specified amount of time to a given date.

{time_add("20-01-2025 15:30:00", 2, "days")} βž” "22-01-2025 15:30:00"

8. time_diff()ΒΆ

Calculates the difference between two dates.

{time_diff("20-01-2025", "22-01-2025", "days")} βž” "2"


Comparing Dates and TimesΒΆ

VisualMaker allows you to compare dates and times to check specific conditions and see if an event has occurred or if there is still time left for it to happen.

You can compare using:

  • Textual dates, e.g., 01-03-2024 02:07:48
  • Functions, e.g., {date_now()}
  • Variables, e.g., {my_variable}

You can also use comparison operators:

  • == Equal to
  • != Not equal to
  • > Greater than
  • < Less than
  • >= Greater than or equal to
  • <= Less than or equal to

This is extremely useful for performing comparisons in actions such as the Condition action.

Example 1: Comparing two textual datesΒΆ

{"02-01-2024 01:02:03" > "01-01-2024 01:02:03"}

This checks if the first date is later (greater) than the second. It will return True, since 02-01-2024 01:02:03 is later than 01-01-2024 01:02:03.

Example 2: Comparing using a variableΒΆ

{"02-01-2024 01:02:03" < my_variable}

This compares if the first date is earlier (less) than the date stored in the variable. It will return True or False, depending on the date stored in the variable.

Example 3: Comparing using a functionΒΆ

{time_passed("15-01-2025 01:01:01", "hours") > 3}
  • The time_passed() function with the "hours" parameter is used here to check how many hours have passed since 15-01-2025 01:01:01. It will return a number indicating the hours that have passed.
  • Then, it checks if that number is greater than 3. If so, it means more than 3 hours have passed, and it will return True. Otherwise, it will return False.

Example 4: Comparing using a function and a variableΒΆ

{time_left(variable_date, "days") == 0}
  • The time_left() function with the "days" parameter is used to check how many days are left until the date stored in the variable_date variable. It will return a number indicating the remaining days.
  • It then checks if that number equals 0. If so, it means the date has already arrived, and it will return True. Otherwise, it will return False.

Note

When using time_left(), once the date has passed, it will always return 0 and will NEVER return negative numbers.


Bot's time zoneΒΆ

  1. Set your bot's time zone in:

    πŸ”‘ Manage β†’ βš™οΈ Settings β†’ πŸ•’ Time zone

  2. The date_now_tz() and apply_tz() functions will respect this setting.


Practical example: Claim button with time conditionΒΆ

In this example, we will create a button called Claim that:

  1. Increases the user's balance by 1 when pressed every 15 minutes.
  2. Saves the claim date.
  3. If the button is pressed before 15 minutes have passed since the last claim, an error will be triggered.

PrerequisitesΒΆ

  1. Premium subscription: These configurations require the use of actions and variables, which are exclusive to the premium subscription in VisualMaker.
  2. Required actions:

Steps to set it up:ΒΆ

1. Create the date variableΒΆ

  1. Go to πŸ”‘ Manage β†’ πŸ—ƒ Variables β†’ πŸ’  Create variable πŸ’ 
  2. In ➑️ Data type:, select date πŸ“….
  3. Enter the variable name, e.g., last_claim.
  4. Exit the manage menu by pressing ↙️ Back β†˜οΈ, then ⬅️ Exit.

2. Create the Claim buttonΒΆ

  1. Enter the bot editor by pressing πŸ›  Edit.
  2. Create a new button by pressing ✳️ New button | command and name it Claim.
  3. Press Actions 🌟 to configure the button's actions.

3. Configure the actionsΒΆ

a) Action 1: ConditionΒΆ
  1. Press 🎯 New action β†’ 🧭 Condition.
  2. For now, don't do anything here (we'll configure it later).
b) Action 2: Change variable (balance)ΒΆ
  1. Press 🎯 New action β†’ πŸ—ƒ Change variable.
  2. Press Configure πŸ›  and set the following:

    • Select variable: Enter the name of the variable to modify:

      balance
      
    • Type of modification:

      πŸ”Ί Increment πŸ”Ί
      
    • Value to save: Specify the value to increment:

      1
      
  3. Return to the actions menu and activate the action by pressing βœ… Activate.

c) Action 3: Change variable (last_claim)ΒΆ
  1. Press 🎯 New action β†’ πŸ—ƒ Change variable.
  2. Press Configure πŸ›  and set the following:

    • Select variable: Enter the name of the variable to modify:

      last_claim
      
    • Type of modification:

      πŸ’’ Set πŸ’’
      
    • Value to save: Specify the date 15 minutes in the future:

      {time_add(date_now(), 15, "minutes")}
      
  3. Return to the actions menu and activate the action by pressing βœ… Activate.

d) Action 4: Send messageΒΆ
  1. Press 🎯 New action β†’ Send message.
  2. Press Configure πŸ›  β†’ πŸ’¬ Set message πŸ’¬ and enter:

    βœ… You have claimed 1 coin, you now have {balance} coins.
    
    πŸ•’ Come back in 15 minutes.
    
  3. Return to the actions menu and activate this action by pressing βœ… Activate.

e) Add a separatorΒΆ

Press New separator πŸ“ to add a separator at the end and create a new block of actions. See what separators are.

f) Action 5: Send messageΒΆ
  1. Press 🎯 New action β†’ Send message.
  2. Press Configure πŸ›  β†’ πŸ’¬ Set message πŸ’¬ and enter:

    ❌ It's not time yet, come back in {floor(time_left(last_claim, "minutes"))} minutes and {ceil(time_left(last_claim, "seconds") % 60)} seconds.
    

    We've used the floor() and ceil() functions to round the number down and up respectively, and time_left() to determine the remaining time in minutes. You can see all functions here.

  3. Return to the actions menu and activate this action by pressing βœ… Activate.

  4. Copy the ID of this action, you will need it soon.
g) Configure the Condition actionΒΆ
  1. Return to the Condition action (action 1) and press Configure πŸ› .

    • New condition:

      {date_now() > last_claim}
      
    • If true: Select continue.

    • If false:
      • Press πŸ†” Execute action by ID πŸ†”.
      • In ➑️ After action:, make sure stop is selected.
      • Enter the ID of the Send message action you copied earlier.
  2. Return to the actions menu and activate this action by pressing βœ… Activate.


Final resultΒΆ

  1. The user presses the Claim button.
  2. The bot checks if 15 minutes have passed since the last claim:

    • If yes:

      1. It increments the user's balance by 1.
      2. Sets a date in the last_claim variable 15 minutes into the future.
      3. Displays a message to the user like:
        βœ… You have claimed 1 coin, you now have 3 coins.
        
        πŸ•’ Come back in 15 minutes.
        
    • If no: It displays a message like:

      ❌ It's not time yet, come back in 9 minutes and 32 seconds.
      

The actions are set up like thisΒΆ

Date and time example (VisualMaker)


With these tools, you can efficiently manage dates and times in VisualMaker, from simple calculations to advanced settings in your bots.