Newer Version Available

This content describes an older version of this product. View Latest

toDate()

Converts a string or Unix epoch seconds to a date. Returns a date that can be used in another function such as daysBetween(​). The returned date cannot be used in a filter.

Syntax

toDate(string [,formatString])

If a formatString argument isn’t provided, the function uses the format yyyy-MM-dd HH:mm:ss

toDate(epoch_seconds)

Be sure to use the sec_epoch field and not the day_epoch field.

Note

Example: Display the Number of Days Since an Opportunity Opened

Suppose that you have an opportunity dataset with the account name and the epoch seconds fields:

Diagram showing the opportunity dataset.

You want to see how many days ago an opportunity was opened. Use daysBetween() and now(). Use toDate() to convert the order date epoch seconds to a date format that can be passed to daysBetween().

1q = load "OpsDates1";
2
3q = foreach q generate Account, daysBetween(toDate(OrderDate_sec_epoch), now()) as 'daysOpened';

The resulting data stream displays the number of days since the opportunity was opened.

Diagram showing the number of days each account has been opened for.