Server Data Formatters - Date and Time

Intro

Below is a comprehensive list of Date and Time formatters available in Server Connect, accompanied by explanations outlining the purpose and functionality of each.

Date and Time Formatters

Format Date:

  • Description: Formats the given date value using the specified format. You can optionally use UTC time instead of local time.
  • Example: ('2021-08-04').formatDate('yyyy-MM-dd HH:mm:ss', true) returns '2021-08-04 00:00:00'

Date Add:

  • Description: Adds a specified number of units to the given date value The value returned is in UTC time. You can add years, months, weeks, days, hours, minutes, seconds. You can also use negative values, this will return a past date and time.
  • Example: ('2021-08-04 12:00:00').dateAdd('days', 3) returns '2021-08-07T00:00:00.000Z'
  • Example: ('2021-08-04 12:00:00').dateAdd('days', -3) returns '2021-08-01T00:00:00.000Z'

Date Diff:

  • Description: Calculates the difference between two date values in various time intervals. The intervals can be years, months, weeks, days, hours, minutes, seconds, hors:minutes, minutes:seconds, hours:minutes:seconds
  • Example: ('2021-08-04').dateDiff('months', '2022-10-04') returns 14

To Timestamp:

  • Description: Converts the given date value to a Unix timestamp.
  • Example: ('2021-08-04 00:00:00').toTimeStamp() returns 1628035200

To Local Time:

  • Description: Converts the given date value to a local time string in the specified format.
  • Example: Assuming our server is in GMT+3
    ('2021-08-04T00:00:00.000Z').toLocalTime() returns '2021-08-04 03:00:00'

To UTC Time:

  • Description: Converts the given date value to an ISO 8601 UTC time string.
  • Example: Assuming our server is in GMT+3
    ('2021-08-04 00:00:00').toUTCTime() returns '2021-08-04T21:00:00.000Z'
7 Likes