4.2 Formula Tool: Date/Time Functions & Type Casting
Key Takeaways
- Alteryx strictly enforces ISO-8601 formats (YYYY-MM-DD for Date, YYYY-MM-DD HH:MM:SS for DateTime, and HH:MM:SS for Time); non-ISO strings cannot be directly treated as temporal types.
- DateTimeAdd() and DateTimeDiff() perform temporal arithmetic across standard units of measure including 'years', 'months', 'days', 'hours', 'minutes', and 'seconds'.
- DateTimeFormat() converts ISO temporal values into custom presentation strings, while DateTimeParse() parses custom formatted strings into standard Alteryx ISO dates.
- ToNumber() converts numeric strings to numbers with options to ignore errors, parse percentages, and specify decimal separators, whereas ToString() formats numbers and dates into text with custom precision and commas.
- Supplying an invalid date string or mismatched format specifier to DateTimeParse() returns a [Null] value and logs a yellow conversion warning in the Results window.
4.2 Formula Tool: Date/Time Functions & Type Casting
Core Concept: Alteryx Designer enforces strict ISO-8601 formatting for native Date and DateTime fields. Transforming strings into valid dates, calculating intervals between timestamps, formatting dates for business reporting, and programmatically converting between numbers and strings are high-yield core exam competencies performed using specialized Date/Time and Conversion functions in the Formula tool.
1. The Alteryx Date & DateTime ISO Standard
Alteryx stores native date and time values using standardized ISO string lengths and formats:
Date: YYYY-MM-DD (10 characters: e.g., '2026-08-28')
Time: HH:MM:SS (8 characters: e.g., '15:30:00' or with subseconds '15:30:00.123')
DateTime: YYYY-MM-DD HH:MM:SS (19 characters: e.g., '2026-08-28 15:30:00')
Any data stored in a Date or DateTime column must strictly conform to these representations. If a field contains dates in formats such as "08/28/2026" or "28-Aug-2026", it is stored as a String or V_WString until converted using DateTimeParse() or the DateTime Tool.
2. Core DateTime Formula Functions
The Formula tool provides a comprehensive suite of functions for generating timestamps, calculating date intervals, and adding durations.
Current System Date and Time
DateTimeToday(): Returns the current system date as an ISODatestring ("YYYY-MM-DD"). Takes no arguments.DateTimeNow(): Returns the current system timestamp as an ISODateTimestring ("YYYY-MM-DD HH:MM:SS"). Takes no arguments.
DateTimeAdd: Adding & Subtracting Intervals
Calculates a future or past date by adding or subtracting an integer duration in specified units.
dt: A valid ISO Date or DateTime field or literal string.val: An integer representing the number of units to add (use positive numbers to add, negative numbers to subtract).uom: Unit of measure string (e.g.,"days","months","years","hours","minutes","seconds","weeks").
// Add 30 days to an order date
DateTimeAdd([Order_Date], 30, "days")
// Subtract 6 months from a reference date
DateTimeAdd([Policy_Renewal], -6, "months")
// Add 4 hours to a timestamp
DateTimeAdd([Log_Time], 4, "hours")
DateTimeDiff: Calculating Elapsed Time
Calculates the difference between two dates ($dt_1 - dt_2$) expressed as an integer in the requested unit of measure.
- Rule: Computes $dt_1 - dt_2$. If $dt_1$ is after $dt_2$, the result is positive. If $dt_1$ is before $dt_2$, the result is negative.
- Integer Truncation:
DateTimeDifftruncates to whole units (does not round up).
// Calculate customer age in full years
DateTimeDiff(DateTimeToday(), [BirthDate], "years")
// Calculate days between shipment and delivery
DateTimeDiff([Delivery_Date], [Ship_Date], "days")
// Calculate overdue days (positive if overdue, negative if remaining)
DateTimeDiff(DateTimeToday(), [Due_Date], "days")
DateTime Interval Units of Measure (uom)
Units of measure are passed as case-insensitive strings:
"years", "months", "weeks", "days", "hours", "minutes", "seconds".
3. Date Formatting & Parsing (DateTimeFormat vs DateTimeParse)
Converting between human-readable date formats and Alteryx ISO standards is a frequent exam requirement.
┌──────────────────────────────────────────────┐
│ Human / Custom Formatted String │
│ "August 28, 2026" │
└───────▲──────────────────────────────┬───────┘
│ │
DateTimeFormat()│ │DateTimeParse()
(Converts Date to Text)│ │(Converts Text to Date)
│ ▼
┌───────┴──────────────────────────────────────┐
│ Alteryx ISO Standard Date │
│ "2026-08-28" │
└──────────────────────────────────────────────┘
DateTimeFormat(dt, format)
Converts a standard ISO Date or DateTime field into a customized string according to format specifiers.
- Example:
DateTimeFormat([OrderDate], "%B %d, %Y")transforms"2026-08-28"into"August 28, 2026". - Target Field Type: Must be a
String,V_String, orV_WString(since custom formats cannot be stored in native Date types).
DateTimeParse(string, format)
Converts a non-ISO date string into a standard Alteryx ISO Date or DateTime (YYYY-MM-DD).
- Example:
DateTimeParse([Date_String], "%m/%d/%Y")transforms"08/28/2026"into"2026-08-28". - Target Field Type:
DateorDateTime.
Comprehensive Format Specifiers Catalog
| Specifier | Description | Example Output / Input |
|---|---|---|
%Y | 4-digit year | 2026 |
%y | 2-digit year (00–99) | 26 |
%m | Month as 2-digit number (01–12) | 08 |
%B | Full month name | August |
%b or %h | Abbreviated 3-letter month name | Aug |
%d | Day of month as 2 digits (01–31) | 28 |
%e | Day of month without leading zero (1–31) | 28 (or 4 for single digits) |
%H | Hour in 24-hour format (00–23) | 14 |
%I | Hour in 12-hour format (01–12) | 02 |
%M | Minute as 2 digits (00–59) | 45 |
%S | Second as 2 digits (00–59) | 09 |
%p | AM or PM designation | PM |
%A | Full weekday name | Friday |
%a | Abbreviated weekday name | Fri |
%j | Day of the year (001–366) | 240 |
Exam Trap: Case sensitivity matters in specifiers!
%Yis a 4-digit year (2026), while%yis a 2-digit year (26).%mis month (01–12), while%Mis minute (00–59).%Bis full month (August), while%bis abbreviated month (Aug).
4. Explicit Type Casting: ToNumber() and ToString()
While the Select tool alters schema types globally, the Formula tool allows programmatic type conversion and string formatting within expressions.
ToNumber() Function
Converts a string representation of a number into a numeric value (Double or integer).
x: The string field to convert.bIgnoreErrors(Optional, default0):0: Generates a conversion error warning in the Results window if non-numeric characters are present, converting invalid values to[Null].1: Suppresses conversion warnings and converts invalid values to0or[Null]quietly.
keepPercents(Optional, default0):0: Ignores%or treats it as non-numeric.1: Automatically divides percentage strings by 100 (e.g.,"85%"converts to0.85).
decimalSymbol(Optional, default"."):- Set to
","to parse European decimal notation (e.g.,"1234,56"→1234.56).
- Set to
// Parse string percentage into decimal without warnings
ToNumber([Discount_Text], 1, 1, ".")
// Convert standard numeric string to number
ToNumber([Unit_Cost])
ToString() Function
Converts a numeric value, date, or boolean into a formatted text string.
x: The numeric value or field to convert.numDec(Optional, default0): Number of decimal places to format (rounds to specified scale).addThousandsSeparator(Optional, default0):0: No commas (e.g.,"1234567.89").1ortrue: Adds commas (e.g.,"1,234,567.89").
decimalSymbol(Optional, default"."): Sets character for decimal point.
// Format revenue as currency string with commas and 2 decimals
"$" + ToString([Revenue], 2, 1)
// Output: "$1,450,200.50"
5. Conversion Errors, Nulls & Error Handling
When temporal or conversion functions encounter malformed data, Designer responds with consistent, deterministic rules:
- Invalid Date Parsing:
DateTimeParse("InvalidDate", "%m/%d/%Y")returns[Null]and logs a Conversion Error in the Results window. - Null Propagation:
DateTimeAdd(Null(), 10, "days")evaluates to[Null]. - Out-of-Bounds Calendar Dates:
DateTimeParse("02/30/2026", "%m/%d/%Y")returns[Null]because February 30th does not exist.
An analyst calculates the tenure of employees using DateTimeDiff([Hire_Date], [Term_Date], 'years'). If an employee was hired on '2020-01-15' and terminated on '2024-06-30', what integer value is returned?
Which Formula expression converts the standard ISO Date '2026-11-05' into the formatted text string '05-Nov-2026'?
A string field contains the value '15%'. Which Formula expression converts this string into the numeric value 0.15 without logging conversion warnings?
An analyst evaluates the expression DateTimeAdd('2026-03-31', -1, 'months'). What date is returned?