Date Function (Node)

  • Guide to date and time functions used in Workflow.

  • _date keyword

    • Provides date-related convenience functions such as creating dates and times, changing formats, and performing operations.

    • Creating date objects ($_date.getDate)

      • Gets the current time.

      // Wed Jul 02 12:00:00 KST 2025
      ${_date.getDate()}
      
    • Creating date objects ($_date.toDate)

      • Converts string or millisecond (long) type values to Date objects.

      • Usage

        • $_date.toDate(format, date_string): Converts a string in the specified format to a Date object.

        • $_date.toDate(milliseconds_number): Converts millisecond values based on January 1, 1970, 00:00:00 to a Date object.

      • Examples

        // String -> Date object
        #set($d1 = $_date.toDate("yyyy-MM-dd HH:mm:ss", "2025-07-02 14:00:00"))
        
        // Milliseconds -> Date object
        #set($d2 = $_date.toDate(1751432400000))
        
    • Changing date format ($_date.format)

      • Usage

        • $_date.format(format, Date_object)

      • Examples

        #set($myDate = $_date.toDate("yyyy-MM-dd HH:mm:ss", "2025-07-02 14:00:00"))
        
        #set($formatDate = ${_date.format("yyyy-MM-dd", $myDate)})
        // Result: 2025-07-02
        $formatDate
        
        // Convert to yyyy-MM-dd HH:mm format string
        ${_date.format("yyyy-MM-dd HH:mm", $myDate)}
        
        // Convert to yy/MM/dd HH:mm format string
        ${_date.format("yy/MM/dd HH:mm", $myDate)}
        
        // Convert current time to yyyy-MM-dd format string
        ${_date.format("yyyy-MM-dd", $_date.getDate()}
        
    • Date operations (toCalendar, add)

      • Performs operations such as adding or subtracting dates.

      • Operations are performed through Calendar objects.

      • Operation procedure

        1. Use $_date.toCalendar(Date_object) to convert a Date object to a Calendar object.

        2. Use the $cal.add(unit, increment_value) method to perform date operations.

        3. Output the operated Calendar object as a string in the desired format through $_date.format.

        4. Major unit constants used in the add method

        Year: 1
        
        Month: 2
        
        Day: 5
        
        Hour: 11
        
        Minute: 12
        
        Second: 13
        
      • Examples

        // Wed Jul 02 12:00:00 KST 2025
        #set($myDate = $_date.getDate())
        
        // Create Calendar object based on myDate
        #set($cal = $_date.toCalendar($myDate))
        
        // Add 10 days, add 10 to Day (5)
        $cal.add(5, 10)
        #set($addDate = $_date.format("yyyy-MM-dd", $cal))
        
        // Result: 2025-07-12
        $addDate
        
        // Important: For new operations, the Calendar object must be reinitialized to the original date
        #set($cal = $_date.toCalendar($myDate))
        
        // Subtract 1 month, subtract 1 from Month (2)
        // If not initialized, the final result would be 2025-06-12, subtracting 1 month from 2025-07-12
        $cal.add(2, -1)
        #set($minusMonth = $_date.format("yyyy-MM-dd", $cal))
        
        // Result: 2025-06-02
        $minusMonth