Code Explainer

Current Date in Eastern Standard Time

This expression retrieves the current date and time in Eastern Standard Time (EST) by converting UTC time, then formats it into a 'yyyy-MM-dd' string, suitable for various applications involving date manipulation.


Empty image or helper icon

Prompt

formatDateTime(convertFromUTC(utcNow(), 'Eastern Standard Time'),'yyyy-MM-dd')

Answer

Code Explanation: formatDateTime(convertFromUTC(utcNow(), 'Eastern Standard Time'),'yyyy-MM-dd')

Overview

The provided code snippet appears to be written in a language or environment that supports date and time manipulation, typically seen in scripting languages such as JavaScript, Power Automate, or Flow expressions.

Function Breakdown

utcNow()

  • Purpose: This function fetches the current date and time in Coordinated Universal Time (UTC).
  • Usage: It is commonly used to get the exact current moment without any time zone offsets.

convertFromUTC(utcTime, timeZone)

  • Purpose: This function converts a given UTC time (utcTime) to a specified time zone (timeZone).
  • Parameters:
    • utcTime: The date and time in UTC that needs to be converted.
    • timeZone: The target time zone to which the UTC time is to be converted, in this case, 'Eastern Standard Time'.
  • Example:
    convertFromUTC(utcNow(), 'Eastern Standard Time')
    Using utcNow() inside convertFromUTC() will convert the current UTC time to Eastern Standard Time (EST).

formatDateTime(dateTime, format)

  • Purpose: This function formats a given date and time (dateTime) into a specified string format (format).
  • Parameters:
    • dateTime: The date and time value to be formatted.
    • format: The string defining the date-time format. Here, 'yyyy-MM-dd' indicates a format of year (4 digits), month (2 digits), and day (2 digits).
  • Example:
    formatDateTime(someDateTime, 'yyyy-MM-dd')

Combined Functionality

formatDateTime(convertFromUTC(utcNow(), 'Eastern Standard Time'), 'yyyy-MM-dd')

This single expression performs the following steps in sequence:

  1. Fetch current UTC time: utcNow()
  2. Convert UTC time to Eastern Standard Time: convertFromUTC(utcNow(), 'Eastern Standard Time')
  3. Format the converted time to 'yyyy-MM-dd': formatDateTime(convertFromUTC(utcNow(), 'Eastern Standard Time'), 'yyyy-MM-dd')

Detailed Explanation

  • Step 1: utcNow()

    • Outputs the current UTC time, e.g., 2023-10-02T14:48:00Z.
  • Step 2: convertFromUTC(utcNow(), 'Eastern Standard Time')

    • Converts the UTC time, e.g., 2023-10-02T10:48:00-04:00 (adjusted to EST).
  • Step 3: formatDateTime(convertFromUTC(utcNow(), 'Eastern Standard Time'), 'yyyy-MM-dd')

    • Formats the EST time into the 'yyyy-MM-dd' format, outputting 2023-10-02.

Summary

The entire expression is used to get the current date in Eastern Standard Time, converting from UTC and then formatting it into a human-readable date string "yyyy-MM-dd".

For deeper learning in date-time manipulations and functions, consider exploring related courses on the Enterprise DNA Platform.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This expression retrieves the current date and time in Eastern Standard Time (EST) by converting UTC time, then formats it into a 'yyyy-MM-dd' string, suitable for various applications involving date manipulation.