Skip to main content

How to receive the current date and time

To get the current date and time, you can use the Current date and time service provided by Aimylogic.

To use it, add the HTTP request block with a GET request and the following URL:

https://tools.aimylogic.com/api/now?tz=Asia/Istanbul&format=dd/MM/yyyy

This URL will return the current date in Turkey, Istanbul, in the dd/MM/yyyy format. Both the time zone and the format can be changed.

To use the data returned by the request, define a variable, e.g. $time, with the $httpResponse value in the HTTP request block:

Filling the HTTP request block

URL parameters

The service supports the following request parameters:

  • tz is the time zone code;
  • format is the time format.
tip
Learn more about the time zone codes and the time format syntax

Either or both of the parameters can be omitted in the request. By default, the service will return the current UTC date and time in the dd.MM.yyyy HH:mm format.

You can check whether you specified the parameters correctly. Paste the request URL into the browser address bar and take a look at the result.

Service response

Response to the request with parameters

For example, the request for the current date and time in Sydney looks as follows:

https://tools.aimylogic.com/api/now?tz=Australia/Sydney&format=dd/MM/yyyy

Current datetime

When the request is made with specifying the additional tz and format parameters, the service returns a JSON which looks as follows:

{
"timezone": "Australia/Sydney",
"formatted": "21/05/2020",
"timestamp": 1590063706359,
"weekDay": 4,
"day": 21,
"month": 5,
"year": 2020,
"hour": 22,
"minute": 21
}

You can use the $time variable or any other variable you specified in the HTTP request block where the service response should be stored further in your script.

For example, you can connect the Success option in the HTTP request block with a Text block that contains the $time variable.

Response to the request without parameters

The request for the current date without any parameters looks as follows:

https://tools.aimylogic.com/api/now

When the request is made without specifying the additional tz and format parameters, the service returns a JSON which looks as follows:

{
"timezone":"Etc/UTC",
"formatted":"17.09.2021 13:18",
"timestamp":1631884709357,
"weekDay":5,
"day":17,
"month":9,
"year":2021,
"hour":13,
"minute":18
}

How to get a particular field from JSON

By default, the Current date and time service gives the response in JSON format. You may need not the whole JSON but a particular field to be used in the script, e.g., a month or a day.

To use a particular field, write the variable as .(field) in the script.

For example, you have saved the full request response in the $time variable. To get the current day in your script, write the variable as $time.day.

Use it for calculations

You can use the date and time information you got for further calculation if you use the Conditions block.