Date Functions and Properties
In this Page
Dates function similarly to Javascript Date objects in which a Date represents the number of milliseconds since midnight January 1, 1970 UTC.
Timestamp formats may differ across different database or APIs. Migrating date information may have unintended results if those differences are not taken into consideration. Time zone settings between Cloudplex and Groundplex might differ since Cloudplex may be in UTC, while a Groundplex could be in a local time zone.
Comparing Dates
Dates can be compared using the relational operators (>, >=, <, <=, ==). For example:
Date.parse("2011-10-10T14:48:00.123-08:00") > Date.parse("2011-10-10T12:48:00.123-08:00") // true // The following is true because a Date is a number of milliseconds since midnight January 1, 1970 UTC Date.parse("2011-10-10T15:48:00.123-08:00") > 1318286880123
The following methods from JavaScript are implemented for Date objects according to local time unless noted otherwise.
now
Description | Returns the current datetime as YYYY-MM-DDTHH:mm:ss.SSS UTC. The results are of the date-time data type. This is similar to the JavaScript now. |
---|---|
Syntax | Date.now() |
Example | Expression: Result: 2017-02-21T21:34:22.025 UTC |
parse
Description | Parses a string representation of a date, and returns it as YYYY-MM-DDTHH:mm:ss.SSS that matches the server's timezone. The results are of the date-time data type. This is similar to the JavaScript parse. |
---|---|
Syntax | Date.parse(dateString) This method has the following extensions from the standard:
|
Example | Expression: Result: 2015-10-27T01:47:49.510 (in the server's timezone) Expression: Result: 2011-10-30T00:00:00.000 (in the server's timezone) Expression: Result: 2015-04-15T13:23:10.000 (in the server's timezone) Expression: Result: 2016-09-23T00:00:00.000 (in the server's timezone) |
UTC
Description | Returns the date/time in universal time. The results are of the date-time data type. This is similar to the JavaScript UTC. |
---|---|
Syntax | Date.UTC(year, month, [day, hour, minute, second, millisecond]) where:
|
Example | Expression: Result: 2015-08-20T13:23:12.034 UTC |
LocalDateTime.parse()
Description | Returns the date in local time. |
---|---|
Syntax | LocalDateTime.parse(_Input_Date) |
Example | Expression: Result: 2011-10-31T00:00:00.000 |
LocalDate.parse()
Description | Returns the date in local time. |
---|---|
Syntax | LocalDate.parse(_Input_Date) |
Example | Expression: Result: 2011-10-31 |
LocalTime.parse()
Description | Returns the date in local time. |
---|---|
Syntax | LocalTime.parse(_Input_Time) |
Example | Expression: Result: 23:42:00.000 |
Getter Methods
getDate
Description | Returns the day of the month for the specified date as an integer between 1 and 31. This is similar to the JavaScript getDate |
---|---|
Syntax | dateobject.getDate() |
Example | Expression: Result: 22 |
getDay
Description | Returns the day of the week for the specified date as an integer, where 0 represents Sunday. This is similar to the JavaScript getDay |
---|---|
Syntax | dateobject.getDay() |
Example | Expression: Date.parse("2014-09-22").getDay() Result: 1 (indicating Monday) |
getFullYear
Description | This is similar to the JavaScript getFullYear - returns the year of the specified date as an integer. |
---|---|
Syntax | dateobject.getFullYear() |
Example | Expression: Result: 2017 |
getHours
Description | This is similar to the JavaScript getHours - returns the hour for the specified date as an integer between 0 and 23. |
---|---|
Syntax | dateobject.getHours() |
Example | Expression: Result: 21 |
getMilliseconds
Description | This is similar to the JavaScript getMilliseconds - returns the milliseconds in the specified date as an integer. |
---|---|
Syntax | dateobject.getMilliseconds() |
Example | Expression: Result: 125 |
getMinutes
Description | This is similar to the JavaScript getMinutes - returns the minutes in the specified date. |
---|---|
Syntax | dateobject.getMinutes() |
Example | Expression: Result: 34 |
getMonth
Description | Returns the month in the specified date as an integer between 1 (January) and 12 (December). This is different from the JavaScript getMonth in that this returns months starting from 1 instead of 0. |
---|---|
Syntax | dateobject.getMonth() |
Example | Expression: Result: 3 |
getMonthfromZero
Description | Returns the month in the specified date as an integer between 0 (January) and 11 (December). Unlike getMonth, this expression is similar to the JavaScript getMonth. |
---|---|
Syntax | dateobject.getMonthFromZero() |
Example | Expression: Result: 2 |
getUTCMonthfromZero
Description | Returns the month according to UTC in the specified date as an integer between 0 (January) and 11 (December). This expression is similar to the JavaScript getUTCMonth. |
---|---|
Syntax | dateobject.getUTCMonthfromZero() |
Example | Expression: Result: 11, 0 |
getSeconds
Description | This is similar to the JavaScript getSeconds - returns the seconds in the specified date as an integer between 0 and 59. |
---|---|
Syntax | dateobject.getSeconds() |
Example | Expression: Result: 22 |
getTime
Description | This is similar to the JavaScript getTime - returns the numeric value corresponding to the time for the specified date according to universal time as the number of milliseconds since 1 January 1970 00:00:00 UTC (epoch time). |
---|---|
Syntax | dateobject.getTime() |
Example | Expression: Date.now().getTime() Result: 1487712862069 |
getUTCDate
Description | Converts the specified time to its corresponding UTC time. |
---|---|
Syntax | dateobject.getUTCDate() |
Example | Expression: Date.parse("2019-03-04T17:32:53.077").getUTCDate() Result: 4 |
getUTCFullYear
Description | Retrieves the year component from the specified date, according to UTC. Values range from 1000 to 9999 |
---|---|
Syntax | dateobject.getUTCFullYear() |
Example | Expression: Date.parse("2019-03-04T17:32:53.077").getUTCFullYear() Result: 2019 |
getUTCMonth
Description | Retrieves the month component from the specified time, according to UTC. Values range from 1 (January) to 12 (December). |
---|---|
Syntax | dateobject.getUTCMonth() |
Example | Expression: Date.parse("2019-03-04T17:32:53.077").getUTCMonth() Result: 3 |
getUTCDay
Description | Returns the day of the week for the specified date, according to UTC. Values range from 0 (Sunday) to 6 (Saturday). |
---|---|
Syntax | dateobject.getUTCDay() |
Example | Expression: Date.parse("2019-03-04T17:32:53.077").getUTCDay() Result: 1 (Monday) |
getUTCHours
Description | Returns the hour component from the specified date, according to UTC. Values range from 0 to 23. |
---|---|
Syntax | dateobject.getUTCHours() |
Example | Expression: Date.parse("2019-03-04T17:32:53.077").getUTCHours() Result: 17 |
getUTCMinutes
Description | Returns the minute component from the specified date, according to UTC. Values range from 0 to 59. |
---|---|
Syntax | dateobject.getUTCMinutes() |
Example | Expression: Date.parse("2019-03-04T17:32:53.077").getUTCMinutes() Result: 32 |
getUTCSeconds
Description | Returns the second component from the specified date, according to UTC. Values range from 0 to 59. |
---|---|
Syntax | dateobject.getUTCSeconds() |
Example | Expression: Date.parse("2019-03-04T17:32:53.077").getUTCSeconds() Result: 53 |
getUTCMilliseconds
Description | Returns the millisecond component from the specified date, according to UTC. Values range from 0 to 999. |
---|---|
Syntax | dateobject.getUTCMilliseconds() |
Example | Expression: Date.parse("2019-03-04T17:32:53.077").getUTCMilliseconds() Result: 77 |
getTimezoneOffset
Description | Returns the time difference (in minutes) between the specified time and the UTC time. |
---|---|
Syntax | dateobject.getTimezoneOffset() |
Example | Expression: Date.parse("2019-03-04T17:32:53.077").getTimezoneOffset() Result: 0 |
Conversion Getter Methods
toString
Description | Returns a string representing the specified Date object. This is similar to the JavaScript toString. |
---|---|
Syntax | dateobject.toString() |
Example | Expression: Result: 2014-09-22T00:00:00.000Z |
toLocaleString
Description | Returns a string with a language-sensitive representation of the date and time. You can specify the formatting conventions of a given language that should be used and customize the behavior of the function. See Database Date Types for compatible date-related formats when data comes from a database. The argument to this method is an object containing the following options that control the format of the returned string:
This is similar to the JavaScript toLocaleString. |
---|---|
Syntax | dateobject.toLocaleString() |
Example | Expressions:
Result: |
toLocaleDateString
Description | Returns a string with a language sensitive representation of the date portion of this date. See Database Date Types for compatible date-related formats when data comes from a database. The argument to this method is an object containing the following options that control the format of the returned string:
Earlier versions of this method would accept a JSON-encoded string as the options object. However, due to the performance impact of parsing this string, it is recommended that an object literal be used to pass the options instead. If your Pipeline passes a string argument, a warning will be raised during execution. This is similar to the JavaScript toLocaleDateString. |
---|---|
Syntax | dateobject.toLocaleDateString() |
Example | Expression: Result: 2014-09-22 Expression: Result: 09-22-2014 Expression:
Result: |
toLocaleDateTimeString
Description | Returns a string with a language sensitive representation of the time portion of this date. See Database Date Types for compatible date-related formats when data comes from a database. The argument to this method is an object containing the following options that control the format of the returned string:
Earlier versions of this method would accept a JSON-encoded string as the options object. However, due to the performance impact of parsing this string, it is recommended that an object literal be used to pass the options instead. If your pipeline passes a string argument, a warning will be raised during execution. This is similar to the JavaScript toLocaleDateTimeString. |
---|---|
Syntax | dateobject.toLocaleDateTimeString() |
Example | Expression: Result: 2024-03-29T00:00:00.000 Expression:
Date.now().toLocaleDateTimeString({"locale":"ar-EG"}) Result: For the {"timeZone":"zoneValue"} option, you can use the Canonical ID value from Joda-Time. Expression:
Result: |
toLocaleTimeString
Description | Returns a string with a language-sensitive representation of the time portion of this date. See Database Date Types for compatible date-related formats when data comes from a database. The argument to this method is an object containing the following options that control the format of the returned string:
Earlier versions of this method would accept a JSON-encoded string as the options object. However, due to the performance impact of parsing this string, it is recommended that an object literal be used to pass the options instead. If your pipeline passes a string argument, a warning will be raised during execution. This is similar to the JavaScript toLocaleTimeString. Date objects do not support the standard setter methods since they are immutable. Instead, you can use the methods described in the next section to produce a new Date object after adding, subtracting, or replacing one of the fields in the object. | ||
---|---|---|---|
Syntax | dateObject.toLocaleTimeString() | ||
Example | Expression: Date.parse("2014-09-22").toLocaleTimeString() Result: 00:00:00.000 Expression:
Result: |
Date Class Extensions
In addition to the above methods, Date objects implement the following methods from the Joda-Time Java library. "Plus" items increase the indicated datetime element by the specified value, "minus" items subtract by the specified value, and "with" replaces the existing data with the specified value.
toLocaleDateString
Description | Format the date using the given format as described in an object. |
---|---|
Syntax | $datetime.toLocaleDateString(format) |
Example | Expression: 'JS_SomeFile' + Date.now().toLocaleDateTimeString({"format":"yyyyMMddhhmmss"}) + '.json' Result: JS_SomeFile20171106112401.json |
plus
Description | Returns a copy of this datetime with the specified duration added. This is similar to the JavaScript plus. |
---|---|
Syntax | $datetime.plus(value) |
Example | If Expression: Date.now().plus(2) Result: 2017-11-06T21:48:11.954 UTC (last digit increased by 2) Expression: Date.now().plus(20) Result: 2017-11-06T21:48:11.972 UTC (second to last digit increased by 2) Expression: Date.now().plus(2000) Result: 2017-11-06T21:48:13.952 UTC (fourth digit from the end increased by 2) |
plusDays
Description | Returns a copy of this datetime plus the specified number of days. This is similar to the JavaScript plusDays. |
---|---|
Syntax | $datetime.plusDays(value) |
Example | If Expression: Date.now().plusDays(2) Result: 2017-11-08T21:48:11.952 UTC (day value increased by 2) |
plusHours
Description | Returns a copy of this datetime plus the specified number of hours. This is similar to the JavaScript plusHours. |
---|---|
Syntax | $datetime.plusHours(value) |
Example | If Expression: Date.now().plusHours(2) Result: 2017-11-06T23:48:11.952 UTC (hour increased by 2) |
plusMillis
Description | Returns a copy of this datetime plus the specified number of milliseconds. This is similar to the JavaScript plusMillis. |
---|---|
Syntax | $datetime.plusMillis(value) |
Example | If Expression: Date.now().plusMillis(2) Result: 2017-11-06T21:48:11.954 UTC (milliseconds increased by 2) |
plusMinutes
Description | Returns a copy of this datetime plus the specified number of minutes. This is similar to the JavaScript plusMinutes. |
---|---|
Syntax | $datetime.plusMinutes(value) |
Example | If Expression: Date.now().plusMinutes(2) Result: 2017-11-06T21:50:11.952 UTC (minutes increased by 2) |
plusMonths
Description | Returns a copy of this datetime plus the specified number of months. This is similar to the JavaScript plusMonths. |
---|---|
Syntax | $datetime.plusMonths(value) |
Example | If Expression: Date.now().plusMonths(2) Result: 2018-01-06T21:48:11.952 UTC (date increased by 2 months) |
plusSeconds
Description | Returns a copy of this datetime plus the specified number of seconds. This is similar to the JavaScript plusSeconds. |
---|---|
Syntax | $datetime.plusSeconds(value) |
Example | If Expression: Date.now().plusSeconds(2) Result: 2017-11-06T21:48:13.952 UTC (time increased by 2 seconds) |
plusWeeks
Description | Returns a copy of this datetime plus the specified number of weeks. This is similar to the JavaScript plusWeeks. |
---|---|
Syntax | $datetime.plusWeeks(value) |
Example | If Expression: Date.now().plusWeeks(2) Result: 2017-11-20T21:48:11.952 UTC (date increased by 2 weeks) |
plusYears
Description | Returns a copy of this datetime plus the specified number of years. This is similar to the JavaScript plusYears. |
---|---|
Syntax | $datetime.plusYears(value) |
Example | If Expression: Date.now().plusYears(2) Result: 2019-11-06T21:48:11.952 UTC (year increased by 2) |
minus
Description | Returns a copy of this datetime with the specified duration subtracted. This is similar to the JavaScript minus. |
---|---|
Syntax | $datetime.minus(value) |
Example | If Expression: Date.now().minus(2) Result: 2017-11-06T21:48:11.950 UTC |
minusDays
Description | Returns a copy of this datetime minus the specified number of days. This is similar to the JavaScript minusDays. |
---|---|
Syntax | $datetime.minusDays(value) |
Example | If Expression: Date.now().minusDays(2) Result: 2017-11-04T21:48:11.952 UTC (day reduced by 2) |
minusHours
Description | Returns a copy of this datetime minus the specified number of hours. This is similar to the JavaScript minusHours. |
---|---|
Syntax | $datetime.minusHours(value) |
Example | If Expression: Date.now().minusHours(2) Result: 2017-11-06T19:48:11.952 UTC (hours reduced by 2) |
minusMillis
Description | Returns a copy of this datetime minus the specified number of milliseconds. This is similar to the JavaScript minusMillis. |
---|---|
Syntax | $datetime.minusMillis(value) |
Example | If Expression: Date.now().minusMillis(2) Result: 2017-11-06T21:48:11.950 UTC (milliseconds reduced by 2) |
minusMinutes
Description | Returns a copy of this datetime minus the specified number of minutes. This is similar to the JavaScript minusMinutes. |
---|---|
Syntax | $datetime.minusMinutes(value) |
Example | If Expression: Date.now().minusMinutes(2) Result: 2017-11-06T21:46:11.952 UTC (minutes reduced by 2) |
minusMonths
Description | Returns a copy of this datetime minus the specified number of months. This is similar to the JavaScript minusMonths. |
---|---|
Syntax | $datetime.minusMonths(value) |
Example | If Expression: Date.now().minusMonths(2) Result: 2017-09-06T21:48:11.952 UTC (months reduced by 2) |
minusSeconds
Description | Returns a copy of this datetime minus the specified number of seconds. This is similar to the JavaScript minusSeconds. |
---|---|
Syntax | $datetime.minusSeconds(value) |
Example | If Expression: Date.now().minusSeconds(2) Result: 2017-11-06T21:48:09.952 UTC |
minusWeeks
Description | Returns a copy of this datetime minus the specified number of weeks. This is similar to the JavaScript minusWeeks. |
---|---|
Syntax | $datetime.minusWeeks(value) |
Example | If Expression: Date.now().minusWeeks(2) Result: 2017-10-23T21:48:11.952 UTC (date decreased by 2 weeks) |
minusYears
Description | Returns a copy of this datetime minus the specified number of years. This is similar to the JavaScript minusYears. |
---|---|
Syntax | $datetime.minusYears(value) |
Example | If Expression: Date.now().minusYears(2) Result: 2015-11-06T21:48:11.952 UTC (year reduced by 2) |
withDayOfMonth
Description | Returns a copy of this datetime with the day of the month field specified. This is similar to the JavaScript withDayOfMonth. |
---|---|
Syntax | $datetime.withDayOfMonth(value) |
Example | If Expression: Date.now().withDayOfMonth(4) Result: 2017-11-04T21:48:11.952 UTC (day changed to 4) |
withDayOfYear
Description | Returns a copy of this datetime with the day of the year field specified This is similar to the JavaScript withDayOfYear. |
---|---|
Syntax | $datetime.withDayOfYear(value) |
Example | If Expression: Date.now().withDayOfYear(4) Result: 2017-01-04T21:48:11.952 UTC (date changed to 01-04 since it is the 4th day of the year) |
withHourOfDay
Description | Returns a copy of this datetime with the hour of day field specified This is similar to the JavaScript withHourOfDay. |
---|---|
Syntax | $datetime.withHourOfDay(value) |
Example | If Expression: Date.now().withHourOfDay(4) Result: 2017-11-06T04:48:11.952 UTC (hours changed to 4) |
withMillisOfSecond
Description | Returns a copy of this datetime with the millis of second field specified. This is similar to the JavaScript withMillisOfSecond. |
---|---|
Syntax | $datetime.withMillisOfSecond(value) |
Example | If Expression: Date.now().withMillisOfSecond(4) Result: 2017-11-06T21:48:11.004 UTC (milliseconds changed to 4) |
withMinuteOfHour
Description | Returns a copy of this datetime with the minute of hour specified. This is similar to the JavaScript withMinuteOfHour. |
---|---|
Syntax | $datetime.withMinuteOfHour(value) |
Example | If Expression: Date.now().withMinuteOfHour(4) Result: 2017-11-06T21:04:11.952 UTC (minutes changed to 4) |
withMonthOfYear
Description | Returns a copy of this datetime with the month of year field specified. This is similar to the JavaScript withMonthOfYear. |
---|---|
Syntax | $datetime.withMonthOfYear(value) |
Example | If Expression: Date.now().withMonthOfYear(4) Result: 2017-04-06T21:48:11.952 UTC (month changed to 4) |
withSecondOfMinute
Description | Returns a copy of this datetime with the second of minute field specified. This is similar to the JavaScript withSecondOfMinute. |
---|---|
Syntax | $datetime.withSecondOfMinute(value) |
Example | If Expression: Date.now().withSecondOfMinute(4) Result: 2017-11-06T21:48:04.952 UTC (seconds changed to 4) |
withYear
Description | Returns a copy of this datetime with the year field specified. This is similar to the JavaScript withYear. |
---|---|
Syntax | $datetime.withYear(value) |
Example | If Expression: $Date.now().withYear(1995) Result: 1995-11-06T21:48:11.952 UTC (year changed to 1995) |
See Also
Video Tutorial: Working with Dates in a Mapper Snap
Have feedback? Email documentation@snaplogic.com | Ask a question in the SnapLogic Community
© 2017-2024 SnapLogic, Inc.