Split Date
Extracts individual date and time components (year, month, day, hour, minute, second, weekday, etc.) from a date/time value and returns them as separate fields in an object. This node is essential for performing conditional logic, filtering, and custom date operations based on specific components.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Input
- Time - The date/time value to split into components. Must be formatted according to the Layout option.
Output
- Parts - An object containing the following date/time components:
year- The 4-digit year (e.g., 2024)month- The month number (1-12, where 1 = January)month_name- The full month name (e.g., "March")day- The day of the month (1-31)year_day- The day of the year (1-366)weekday- The day of the week as a number (0-6, where 0 = Sunday)weekday_name- The full weekday name (e.g., "Friday")minute- The minute (0-59)second- The second (0-59)
Note: The output does not include an hour field in the current implementation. If you need the hour component, you can extract it using the Format Time node with a custom format or parse it from the original time string.
Options
- Layout - The date/time format of the input time. Options include:
- ANSIC -
Mon Jan 2 15:04:05 2006 - UnixDate -
Mon Jan 2 15:04:05 MST 2006 - RubyDate -
Mon Jan 02 15:04:05 -0700 2006 - RFC822 -
02 Jan 06 15:04 MST - RFC822Z -
02 Jan 06 15:04 -0700 - RFC850 -
Monday, 02-Jan-06 15:04:05 MST - RFC1123 -
Mon, 02 Jan 2006 15:04:05 MST - RFC1123Z -
Mon, 02 Jan 2006 15:04:05 -0700 - RFC3339 -
2006-01-02T15:04:05-07:00(default, ISO 8601) - RFC3339Nano -
2006-01-02T15:04:05.000000000-07:00 - Custom - Define a custom format
- ANSIC -
How It Works
The Split Date node parses a date/time string and extracts all components by:
- Parsing the input time according to the specified Layout
- Extracting each date and time component
- Creating an object with all components as separate fields
- Outputting the object for use in subsequent nodes
Use Cases
Conditional Logic
- Execute different actions based on day of week
- Filter data by month or year
- Apply business rules based on date components
Date Filtering
- Process records from specific months
- Identify weekend vs. weekday data
- Filter by quarter or season
Custom Formatting
- Build custom date strings using individual components
- Create localized date displays
- Generate specialized date representations
Date Analysis
- Calculate quarterly reports
- Identify patterns by day of week
- Group data by month or year
Business Logic
- Apply different rates based on month
- Implement day-of-week specific rules
- Handle special cases for specific dates
Examples
Example 1: Split a Standard Date
Time: 2024-03-15T14:30:45Z
Layout: RFC3339
Output:
{
"year": 2024,
"month": 3,
"month_name": "March",
"day": 15,
"year_day": 75,
"weekday": 5,
"weekday_name": "Friday",
"minute": 30,
"second": 45
}
Example 2: First Day of Year
Time: 2024-01-01T00:00:00Z
Layout: RFC3339
Output:
{
"year": 2024,
"month": 1,
"month_name": "January",
"day": 1,
"year_day": 1,
"weekday": 1,
"weekday_name": "Monday",
"minute": 0,
"second": 0
}
Example 3: Leap Year Day
Time: 2024-02-29T12:00:00Z
Layout: RFC3339
Output:
{
"year": 2024,
"month": 2,
"month_name": "February",
"day": 29,
"year_day": 60,
"weekday": 4,
"weekday_name": "Thursday",
"minute": 0,
"second": 0
}
Component Reference
Weekday Numbers
- 0 = Sunday
- 1 = Monday
- 2 = Tuesday
- 3 = Wednesday
- 4 = Thursday
- 5 = Friday
- 6 = Saturday
Month Numbers
- 1 = January
- 2 = February
- 3 = March
- 4 = April
- 5 = May
- 6 = June
- 7 = July
- 8 = August
- 9 = September
- 10 = October
- 11 = November
- 12 = December
Year Day
- Ranges from 1 to 365 (or 366 in leap years)
- January 1 = 1
- December 31 = 365 (or 366)
Accessing Components
After splitting the date, you can access individual components using dot notation:
// Access year
var year = msg.parts.year;
// Access month name
var monthName = msg.parts.month_name;
// Access day of week
var dayOfWeek = msg.parts.weekday;
// Check if it's a weekend
var isWeekend = msg.parts.weekday === 0 || msg.parts.weekday === 6;
// Check if it's a specific month
var isDecember = msg.parts.month === 12;
Workflow Examples
Example 1: Execute Different Logic for Weekends
- Get current date using Now node
- Use Split Date node to extract components
- Use If node: Check
msg.parts.weekday === 0 || msg.parts.weekday === 6 - If true: Execute weekend workflow
- If false: Execute weekday workflow
Example 2: Generate Monthly Reports
- Get date from record
- Use Split Date to extract month
- Group records by
msg.parts.month - Generate report for each month
Example 3: Filter Data by Quarter
- Get record date
- Use Split Date to extract month
- Calculate quarter using JavaScript:
var quarter = Math.ceil(msg.parts.month / 3);
msg.quarter = quarter; - Filter by desired quarter
Example 4: Check Business Hours
- Get current time using Now node
- Use Split Date to extract weekday
- Check if weekday is 1-5 (Monday-Friday)
- Also check hour range (requires separate hour extraction)
Example 5: Birthday Reminder
- Get user's birthdate
- Use Split Date to extract month and day
- Compare with current month and day
- Send reminder if match
Tips for Effective Use
- Store Components - Save the parts object to a message property for reuse across multiple nodes
- Weekday Logic - Remember Sunday = 0, Monday = 1, making weekend checks straightforward
- Month Names - Use
month_namefor user-facing displays,monthnumber for calculations - Year Day - Useful for calculating "day X of year" metrics or identifying specific dates
- Combine with If Node - Use extracted components in conditional statements for routing logic
- Quarter Calculations - Calculate quarters with:
Math.ceil(month / 3) - Season Calculations - Determine seasons based on month number
- Missing Hour - If you need the hour component, use Format Time with custom format to extract it separately
Common Errors and Solutions
Error: "failed to parse input time"
- Cause: Input time format doesn't match the Layout specification
- Solution: Ensure the input time is formatted according to the selected Layout
Error: "time is required"
- Cause: No value provided for the Time input
- Solution: Provide a valid date/time string in the Time input field
Undefined component when accessing
- Cause: Typo in component name or trying to access non-existent component
- Solution: Verify the component name matches exactly (e.g.,
month_name, notmonthName)
Hour component not available
- Cause: The hour field is not included in the output object
- Solution: Use Format Time node with custom format
15to extract the hour, or parse it from the original time string
Practical Examples
Example: Filter Weekend Orders
// After Split Date node
if (msg.parts.weekday === 0 || msg.parts.weekday === 6) {
msg.orderType = "Weekend Order";
// Apply weekend pricing
} else {
msg.orderType = "Weekday Order";
// Apply regular pricing
}
Example: Generate Fiscal Quarter
// After Split Date node
var month = msg.parts.month;
// For fiscal year starting in April
var fiscalMonth = month < 4 ? month + 9 : month - 3;
msg.fiscalQuarter = Math.ceil(fiscalMonth / 3);
msg.fiscalYear = month < 4 ? msg.parts.year - 1 : msg.parts.year;
Example: Check Holiday (Christmas)
// After Split Date node
if (msg.parts.month === 12 && msg.parts.day === 25) {
msg.isHoliday = true;
msg.holidayName = "Christmas";
}
Example: Calculate Age in Years
// Split current date
var currentYear = msg.currentParts.year;
var currentMonth = msg.currentParts.month;
var currentDay = msg.currentParts.day;
// Split birthdate
var birthYear = msg.birthParts.year;
var birthMonth = msg.birthParts.month;
var birthDay = msg.birthParts.day;
// Calculate age
var age = currentYear - birthYear;
if (currentMonth < birthMonth ||
(currentMonth === birthMonth && currentDay < birthDay)) {
age--;
}
msg.age = age;
Related Nodes
- Format Time - Convert date formats or extract specific components
- Now - Get current date to split
- Is Leap Year - Check if the extracted year is a leap year
- Add Time - Modify dates based on extracted components