This module contains functions to create and manipulate Date types.
To use this module, you must import it to your DataWeave code, for example,
by adding the line import * from dw::core::Dates
to the header of your
DataWeave script.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Functions
atBeginningOfDay
atBeginningOfDay(dateTime: DateTime): DateTime
Returns a new DateTime
value that changes the Time
value in the input to the
beginning of the specified day.
The hours, minutes, and seconds in the input change to 00:00:00
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Time
value within the DateTime
input to the
beginning of the specified day.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
"atBeginningOfDayDateTime": atBeginningOfDay(|2020-10-06T18:23:20.351-03:00|)
}
Output
1
2
3
{
"atBeginningOfDayDateTime": "2020-10-06T00:00:00-03:00"
}
atBeginningOfDay(localDateTime: LocalDateTime): LocalDateTime
Returns a new LocalDateTime
value that changes the Time
value within the
input to the start of the specified day.
The hours, minutes, and seconds in the input change to 00:00:00
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Time
value within the LocalDateTime
input to the
beginning of the specified day.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
"atBeginningOfDayLocalDateTime": atBeginningOfDay(|2020-10-06T18:23:20.351|)
}
Output
1
2
3
{
"atBeginningOfDayLocalDateTime": "2020-10-06T00:00:00"
}
atBeginningOfHour
atBeginningOfHour(dateTime: DateTime): DateTime
Returns a new DateTime
value that changes the Time
value in the input to the
beginning of the specified hour.
The minutes and seconds in the input change to 00:00
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Time
value within the DateTime
input to the
beginning of the specified hour.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
"atBeginningOfHourDateTime": atBeginningOfHour(|2020-10-06T18:23:20.351-03:00|)
}
Output
1
2
3
{
"atBeginningOfHourDateTime": "2020-10-06T18:00:00-03:00"
}
atBeginningOfHour(localDateTime: LocalDateTime): LocalDateTime
Returns a new LocalDateTime
value that changes the Time
value in the input to the
beginning of the specified hour.
The minutes and seconds in the input change to 00:00
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Time
value within the LocalDateTime
input to the
beginning of the specified hour.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
"atBeginningOfHourLocalDateTime": atBeginningOfHour(|2020-10-06T18:23:20.351|)
}
Output
1
2
3
{
"atBeginningOfHourLocalDateTime": "2020-10-06T18:00:00"
}
atBeginningOfHour(localTime: LocalTime): LocalTime
Returns a new LocalTime
value that changes its value in the input to the
beginning of the specified hour.
The minutes and seconds in the input change to 00:00
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the LocalTime
value to the
beginning of the specified hour.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
"atBeginningOfHourLocalTime": atBeginningOfHour(|18:23:20.351|)
}
Output
1
2
3
{
"atBeginningOfHourLocalTime": "18:00:00"
}
atBeginningOfHour(time: Time): Time
Returns a new Time
value that changes the input value to the
beginning of the specified hour.
The minutes and seconds in the input change to 00:00
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Time
value to the beginning of the specified hour.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
"atBeginningOfHourTime": atBeginningOfHour(|18:23:20.351-03:00|)
}
Output
1
2
3
{
"atBeginningOfHourTime": "18:00:00-03:00"
}
atBeginningOfMonth
atBeginningOfMonth(dateTime: DateTime): DateTime
Returns a new DateTime
value that changes the Day
value from the
input to the first day of the specified month. It also sets the Time
value to 00:00:00
.
The day and time in the input changes to 01T00:00:00
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Day
value within the DateTime
input to the
first day of the specified month and sets the Time
value to 00:00:00
.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
"atBeginningOfMonthDateTime": atBeginningOfMonth(|2020-10-06T18:23:20.351-03:00|)
}
Output
1
2
3
{
"atBeginningOfMonthDateTime": "2020-10-01T00:00:00-03:00"
}
atBeginningOfMonth(localDateTime: LocalDateTime): LocalDateTime
Returns a new LocalDateTime
value that changes the Day
and LocalTime
values from the input to the beginning of the specified month.
The day and time in the input changes to 01T00:00:00
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Day
and LocalTime
values within the LocalDateTime
input to the beginning of the specified month.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
"atBeginningOfMonthLocalDateTime": atBeginningOfMonth(|2020-10-06T18:23:20.351|)
}
Output
1
2
3
{
"atBeginningOfMonthLocalDateTime": "2020-10-01T00:00:00"
}
atBeginningOfMonth(date: Date): Date
Returns a new Date
value that changes the Day
value from the
input to the first day of the specified month.
The day in the input changes to 01
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Day
value within the Date
input to the first day of the specified month.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
atBeginningOfMonthDate: atBeginningOfMonth(|2020-10-06|)
}
Output
1
2
3
{
"atBeginningOfMonthDate": "2020-10-01"
}
atBeginningOfWeek
atBeginningOfWeek(dateTime: DateTime): DateTime
Returns a new DateTime
value that changes the Day
and Time
values from the
input to the beginning of the first day of the specified week.
The function treats Sunday as the first day of the week.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Day
and Time
values (06T18:23:20.351
) within
the DateTime
input to the beginning of the first day of the specified week
(04T00:00:00
).
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
atBeginningOfWeekDateTime: atBeginningOfWeek(|2020-10-06T18:23:20.351-03:00|)
}
Output
1
2
3
{
"atBeginningOfWeekDateTime": "2020-10-04T00:00:00-03:00"
}
atBeginningOfWeek(localDateTime: LocalDateTime): LocalDateTime
Returns a new LocalDateTime
value that changes the Day
and Time
values from the
input to the beginning of the first day of the specified week.
The function treats Sunday as the first day of the week.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Day
and Time
values (06T18:23:20.351
) within
the LocalDateTime
input to the beginning of the first day of the specified week
(04T00:00:00
).
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
atBeginningOfWeekLocalDateTime: atBeginningOfWeek(|2020-10-06T18:23:20.351|)
}
Output
1
2
3
{
"atBeginningOfWeekLocalDateTime": "2020-10-04T00:00:00"
}
atBeginningOfWeek(date: Date): Date
Returns a new Date
value that changes the Date
input
input to the first day of the specified week.
The function treats Sunday as the first day of the week.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example changes the Day
value (06
) within
the Date
input to the first day of the week that contains 2020-10-06
(a Tuesday), which is 2020-10-04
(a Sunday).
The Day
value changes from 06
to 04
.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
atBeginningOfWeekDate: atBeginningOfWeek(|2020-10-06|)
}
Output
1
2
3
{
"atBeginningOfWeekDate": "2020-10-04"
}
atBeginningOfYear
atBeginningOfYear(dateTime: DateTime): DateTime
Takes a DateTime
value as input and returns a DateTime
value for
the first day of the year specified in the input. It also sets the Time
value to 00:00:00
.
The month, day, and time in the input changes to 01-01T00:00:00
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example transforms the DateTime
input (|2020-10-06T18:23:20.351-03:00|
)
to the date of the first day of the Year
value (2020
) in the input.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
atBeginningOfYearDateTime: atBeginningOfYear(|2020-10-06T18:23:20.351-03:00|)
}
Output
1
2
3
{
"atBeginningOfYearDateTime": "2020-01-01T00:00:00.000-03:00"
}
atBeginningOfYear(localDateTime: LocalDateTime): LocalDateTime
Takes a LocalDateTime
value as input and returns a LocalDateTime
value for
the first day of the year specified in the input. It also sets the Time
value to 00:00:00
.
The month, day, and time in the input changes to 01-01T00:00:00
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example transforms the LocalDateTime
input (|2020-10-06T18:23:20.351|
)
to the date of the first day of the Year
value (2020
) in the input.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
atBeginningOfYearLocalDateTime: atBeginningOfYear(|2020-10-06T18:23:20.351|)
}
Output
1
2
3
{
"atBeginningOfYearLocalDateTime": "2020-01-01T00:00:00"
}
atBeginningOfYear(date: Date): Date
Takes a Date
value as input and returns a Date
value for
the first day of the year specified in the input.
The month and day in the input changes to 01-01
.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
The |
Example
This example transforms Date
input (|2020-10-06|
) to the date of the
first day of the Year
value (2020
) in the input.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
atBeginningOfYearDate: atBeginningOfYear(|2020-10-06|)
}
Output
1
2
3
{
"atBeginningOfYearDate": "2020-01-01"
}
date
date(parts: DateFactory): Date
Creates a Date
value from values specified for year
, month
, and day
fields.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
|
Example
This example shows how to create a value of type Date
.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
newDate: date({year: 2012, month: 10, day: 11})
}
Output
1
2
3
{
"newDate": "2012-10-11"
}
dateTime
dateTime(parts: DateTimeFactory): DateTime
Creates a DateTime
value from values specified for month
, day
, hour
,
minutes
, seconds
, and timezone
fields.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
|
Example
This example shows how to create a value of type DateTime
.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
newDateTime: dateTime({year: 2012, month: 10, day: 11, hour: 12, minutes: 30, seconds: 40 , timeZone: |-03:00|})
}
Output
1
2
3
{
"newDateTime": "2012-10-11T12:30:40-03:00"
}
localDateTime
localDateTime(parts: LocalDateTimeFactory): LocalDateTime
Creates a LocalDateTime
value from values specified for year
, month
, day
,
hour
, minutes
, and seconds
fields.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
|
Example
This example shows how to create a value of type LocalDateTime
.
Source
1
2
3
4
5
6
7
%dw 2.0
import * from dw::core::Dates
output application/json
---
{
newLocalDateTime: localDateTime({year: 2012, month: 10, day: 11, hour: 12, minutes: 30, seconds: 40})
}
Output
1
2
3
{
"newLocalDateTime": "2012-10-11T12:30:40"
}
localTime
localTime(parts: LocalTimeFactory): LocalTime
Creates a LocalTime
value from values specified for hour
, minutes
, and
seconds
fields.
Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.
Parameters
Name | Description |
---|---|
|
|
Example
This example shows how to create a value of type LocalTime
.
Source
%dw 2.0 import * from dw::core::Dates output application/json --- { newLocalTime: localTime({ hour: 12, minutes: 30, seconds: 40}) }
====== Output [source,Json,linenums]
{ "newLocalTime": "12:30:40" }
=== time ==== time(parts: TimeFactory): Time Creates a `Time` value from values specified for `hour`, `minutes`, `seconds`, and `timezone` fields. _Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later._ ===== Parameters [%header, cols="1,3"] |=== | Name | Description | `parts` | `Number` values for `hour`, `minutes`, and `seconds` fields, and a `TimeZone` value for the `timezone` field. Valid values are 0 through 23 for the `hour`, 0 through 59 for `minutes`, and 0 through 60 (not inclusive; it can accept 59.99, for example) for `seconds` fields. The `timezone` must be a valid `TimeZone` value, such as `|-03:00|` You can specify the name-value pairs in any order, but the output is ordered as a default `Time` value, such as `10:10:10-03:00`. The input fields are parts of a `TimeFactory` type. |=== ===== Example This example shows how to create a value of type `Time`. ====== Source [source,DataWeave,linenums]
%dw 2.0 import * from dw::core::Dates output application/json --- { newTime: time({ hour: 12, minutes: 30, seconds: 40 , timeZone: |-03:00|}) }
====== Output [source,Json,linenums]
{ "newTime": "12:30:40-03:00" }
=== today ==== today(): Date Returns the date for today as a `Date` type. _Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later._ ===== Example This example shows the output of `today` function. ====== Source [source,DataWeave,linenums]
%dw 2.0 import * from dw::core::Dates output application/json --- today()
====== Output [source,Json,linenums]
"2021-05-15"
=== tomorrow ==== tomorrow(): Date Returns the date for tomorrow as a `Date` type. _Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later._ ===== Example This example shows the output of `tomorrow` function. ====== Source [source,DataWeave,linenums]
%dw 2.0 import tomorrow from dw::core::Dates output application/json --- tomorrow()
====== Output [source,Json,linenums]
"2021-05-16"
=== yesterday ==== yesterday(): Date Returns the date for yesterday as a `Date` type. _Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later._ ===== Example This example shows the output of `yesterday` function. ====== Source [source,DataWeave,linenums]
%dw 2.0 import * from dw::core::Dates output application/json --- yesterday()
====== Output [source,Json,linenums]
"2021-05-14"
== Types === DateFactory Type containing selectable `day`, `month`, and `year` keys and corresponding `Number` values, such as `{day: 21, month: 1, year: 2021}`. The fields accept a `Number` value. Numbers preceded by `0`, such as `01`, are not valid. .Definition [source,DataWeave,linenums]
{ day: Number, month: Number, year: Number }
=== DateTimeFactory Type that combines `DateFactory`, `LocalTimeFactory`, and `Zoned` types. For example, `{day: 21, month: 1, year: 2021, hour: 8, minutes: 31, seconds: 55, timeZone : |-03:00|} as DateTimeFactory` is a valid `DateTimeFactory` value. .Definition [source,DataWeave,linenums]
DateFactory & LocalTimeFactory & Zoned
=== LocalDateTimeFactory Type that combines `DateFactory` and `LocalTimeFactory` types. For example, `{day: 21, month: 1, year: 2021, hour: 8, minutes: 31, seconds: 55, timeZone : |-03:00|} as LocalDateTimeFactory` is a valid `LocalDateTimeFactory` value. The `timeZone` field is optional. .Definition [source,DataWeave,linenums]
DateFactory & LocalTimeFactory
=== LocalTimeFactory Type containing selectable `hour`, `minutes`, and `seconds` keys and corresponding `Number` values, such as `{hour: 8, minutes: 31, seconds: 55}`. The fields accept any `Number` value. .Definition [source,DataWeave,linenums]
{ hour: Number, minutes: Number, seconds: Number }
=== TimeFactory Type that combines `LocalTimeFactory` and `Zoned` types. For example, `{hour: 8, minutes: 31, seconds: 55, timeZone : |-03:00|} as TimeFactory` is a valid `TimeFactory` value. .Definition [source,DataWeave,linenums]
LocalTimeFactory & Zoned
=== Zoned Type containing a selectable `timeZone` key and `TimeZone` value, such as `{ timezone : |-03:00|}`. .Definition [source,DataWeave,linenums]
{ timeZone: TimeZone }