Skip to content

Updating visuals

If you see any images containing outdated UI, please bear with us.

We are updating all content as quickly as possible to mirror our new UI.

Date formulas ​

Date formulas are useful to manipulate date objects inside WeWeb.

Where to find date formulas ​

Date formulas are built into every WeWeb project, so there is nothing to install. You'll be able to see all the related no-code formulas in the Date category of the Formulas tab of the binding window:

The Date category in the Formulas tab of the binding window, listing every date formula

TIP

Working with dates can be tricky at first. If you get stuck on formatting, we recommend you go through this article on the ISO date format.

date ​

If you use date in a formula with no parameters, you will get the current date and time in Coordinated Universal Time (i.e. the UTC timezone).

The no-code date formula can take the same parameters as the JavaScript new Date() function.

dateRealtime ​

Same as date, dateRealtime will return the current date and time in Coordinated Universal Time (i.e. the UTC timezone).

That date, however, will be updated every second in real-time:

Realtime date formula

toDateISO ​

This formula allows you to set a date in ISO format. It only takes one parameter: the date.

The toDateISO formula with a single date parameter and its ISO result in the Current value field

If you want to display the date in a specific format, use the formatDate formula instead.

formatDate ​

This formula allows you to format a date:

The formatDate formula with a date, the dddd D MMMM YYYY format and the es language, returning sábado 23 marzo 2024

In the example above, you see:

  • First we start with a date formula that returns a date in ISO format,
  • Then we wrap the formatDate formula around it, which displays the date as YYYY-MM-DD when no format is given,
  • We add a second parameter to the formatDate formula to display the date in a different format,
  • Finally, we change the display language to Spanish. When you don't set a language, WeWeb uses the current language of your app.

Here are the codes you can use in the format:

CodeShowsExample
YYYY / YYYear2024 / 24
MMMM / MMMMonth name, full or shortMarch / Mar
MM / MMonth number, with or without a leading zero03 / 3
DD / DDay of the month, with or without a leading zero09 / 9
dddd / ddd / ddDay of the week, full, short or narrowSaturday / Sat / S
HH / HHour, 24-hour clock14
hh / hHour, 12-hour clock02 / 2
mm / mMinutes30
ss / sSeconds45
SSSMilliseconds250
A / aAM or PMPM / pm

To show text as it is, put it between square brackets. For example, "[Today is] dddd" returns Today is Saturday.

WARNING

Codes are case sensitive. MM is the month and mm is the minutes, so make sure to write HH:mm and not HH:MM to display the hour and minutes.

toTime ​

This formula calculates the time between now and X, and returns the information in text format:

toTime formula

In the toTime formula, the relative time compares the date now, to the date in the first parameter.

For example, if today is August 23rd, 2024:

  • June 23rd, 2024 was "2 months ago"
  • June 23rd, 2025 is "in 10 months"

The formula will accept the following parameters:

  • A date in ISO format (required),
  • Whether to remove the suffix ("ago" or "in") or not (optional), and
  • The language in which the text should be displayed (optional)

fromTime ​

This formula returns the same result as toTime: it calculates the time between X and now, and returns the information in a text format.

For example, if today is August 23rd, 2024:

  • June 23rd, 2024 was "2 months ago"
  • June 23rd, 2025 is "in 10 months"

The formula will accept the following parameters:

  • A date in ISO format (required),
  • Whether to remove the suffix ("ago" or "in") or not (optional), and
  • The language in which the text should be displayed (optional)

compareDate ​

This formula allows you to compare two dates:

compareDate formula

The result is the second date minus the first date, so it is negative if the second date is earlier.

You can count the number of:

  • Years (year),
  • Months (month),
  • Weeks (week),
  • Days (day),
  • Hours (hour),
  • Minutes (minute),
  • Seconds (second), or
  • Milliseconds (millisecond), which is the default when you leave the unit empty.

TIP

When you hover over a no-code formula name in the WeWeb, you can view tooltips on what parameters and values it expects.

By default, the result of the compareDate formula will be a round number.

If the floating parameter is true, you can see decimals in the calculation. For example, there are 4.6 months between November 4th, 2023 and March 23rd, 2024:

compareDate formula with floating

When counting in months, a month is about 30.4 days, and when counting in years, a year is 365 days.

getX ​

These formulas allow you to get one part of a date, as a number. If you leave the date empty, they use the current date and time:

  • getSecond — the seconds, from 0 to 59
  • getMinute — the minutes, from 0 to 59
  • getHour — the hour, from 0 to 23
  • getDay — the day of the month, from 1 to 31
  • getDayOfWeek — the day of the week, from 0 (Sunday) to 6 (Saturday)
  • getMonth — the month, from 1 (January) to 12 (December)
  • getYear — the year, e.g. 2024
  • getDayOfYear — the day of the year, from 1 to 366
  • getWeekOfYear — the week of the year

These formulas use the timezone of your user's browser.

addX ​

These formulas allow you to add time to a date, and return the new date in ISO format. The first parameter is the date, the second is the amount to add. Use a negative amount to go back in time:

  • addSeconds
  • addMinutes
  • addHours
  • addDays
  • addMonths
  • addYears

For example, addDays("2024-03-23T00:00:00Z", 7) returns "2024-03-30T00:00:00.000Z".

addWorkdays ​

The addWorkdays formula allows you to add working days to a date, skipping weekends (Saturday and Sunday). It's useful to calculate a delivery date or a deadline.

The formula will accept the following parameters:

  • A date (required),
  • The number of working days to add (required). It must be a whole number, and you can use a negative number to go back in time, and
  • Holidays to skip (optional), as a list of dates like ["2024-12-25", "2025-01-01"] or as text separated by commas like "2024-12-25,2025-01-01". Each holiday must be written as YYYY-MM-DD

For example, addWorkdays("2024-05-24T12:30:00Z", 1, "2024-05-27") returns "2024-05-28T12:30:00.000Z": May 24th is a Friday, the weekend is skipped, and May 27th is a holiday.

The time of day stays the same, and you can add up to 10,000 working days.

workdayDiff ​

The workdayDiff formula allows you to count the working days between two dates, without weekends and holidays.

The formula will accept the following parameters:

  • The start date (required),
  • The end date (required), and
  • Holidays to skip (optional), in the same format as for addWorkdays

Both the start date and the end date are counted. For example, from Monday to Friday of the same week, the result is 5. If the end date is before the start date, the result is negative.

setX ​

These formulas allow you to replace one part of a date, and return the new date in ISO format. The first parameter is the date, the second is the new value:

  • setSecond
  • setMinute
  • setHour
  • setDay — the day of the month
  • setDayOfWeek — from 0 (Sunday) to 6 (Saturday), within the same week
  • setMonth — from 1 (January) to 12 (December)
  • setYear

For example, setMonth("2024-03-23T00:00:00Z", 12) returns a date in December 2024.

toTimestamp ​

The toTimestamp formula expects a date in ISO format and will return the timestamp value for that date in a number format:

toTimestamp formula

getBrowserTimezone ​

The getBrowserTimezone formula will return the timezone your user's browser is in.

Get user's browser timezone

convertDateTimezone ​

The convertDateTimezone formula allows you to display a different date and time depending on the user's timezone.

The first parameter must be a date that contains time and timezone information. The second parameter is the timezone, e.g. "America/New_York".

For example, the date formula returns the date and time in the UTC timezone. Here, we are converting the current date and time to the date and time in New York:

Convert date timezone

The result will show the date and time in the new timezone, written as YYYY-MM-DDTHH:mm:ss, without timezone information.

formatDateTimezone ​

The formatDateTimezone formula allows you to take a date provided in ISO format, and display it:

  • In the format of your choice, e.g. "MMMM D, YYYY - HH:mm", with the same codes as formatDate (YYYY-MM-DD by default)
  • Converted to the timezone of your choice, e.g. "America/Mexico_City" (the timezone of your user's browser by default)
  • In the language of your choice, e.g. es for Spanish (the current language of your app by default)
The formatDateTimezone formula with the MMMM D, YYYY - HH:mm format, the America/Mexico_City timezone and the es language, returning noviembre 29, 2023 - 19:30

Troubleshooting ​

Working with dates can be tricky at first.

Here are a few things to consider when a date formula is not behaving as you would expect:

  1. ISO date values and date formats should be strings. Make sure to enclose them in between quotes "like_this"

  2. Timestamp values should be numbers. If you are storing timestamps in a text format, use the toNumber formula around it to convert it so the date formulas can work with it

  3. ISO date formats are easy to mess up. When in doubt, check out this article with numerous examples of ISO date formats

  4. Format codes are case sensitive: MM is the month and mm is the minutes

  5. Holidays in addWorkdays and workdayDiff should be written as YYYY-MM-DD, without a time