Skip to main content

Celonis Product Documentation

ADD_MILLIS
Description

ADD_MILLIS adds a given number of milliseconds to a given timestamp. If a calendar is specified, only the passed time in the calendar is considered.

Supported input column types: start_column -> DATE, milliseconds_column -> INT

Output column type: DATE

If a calendar is specified and the start timestamp is not covered by the given calendar, ADD_MILLIS returns the same result as if the start timestamp was the first timestamp after the start that is covered by the calendar.

If a result of type DATE is outside the interval from the year 1400 CE (including) to the year 10000 CE (excluding), it will be mapped to NULL. Additionally if a calendar is specified, NULL is returned, if the start timestamp is outside of the scope of the calendar or if the result would lie outside of the scope. For the factory calendar the scope contains the complete year containing the first defined shift (so also all days before the first shift in that year), the complete year containing the last defined shift and all years in between.

Syntax
  ADD_MILLIS ( start_column, milliseconds_column [, calendar_specification [, calendar_id_column]])
 
  • start_column: Start timestamp

  • milliseconds_column: Number of milliseconds which are added to the start timestamp (can be negative)

  • calendar_specification: One of WEEKDAY_CALENDAR, FACTORY_CALENDAR, WORKDAY_CALENDAR, or INTERSECT

  • calendar_id_column: Column to create a mapping between the respective activities and their used calendar specification. This is mandatory when using multiple calendar specifications. For more details, please take a look at the respective documentation of the DateTime Calendar.

NULL handling

If any parameter is NULL, the result is NULL as well.

Exceptions

The ADD_MILLIS operator does not work if there are any gaps in the years covered by the respective WORKDAY_CALENDAR. An error will be returned if gaps are found in the workday calendar configuration.

Examples

[1]

A simple example for ADD_MILLIS without a calendar.

Query

Column1

         ADD_MILLIS ( "Table1"."Timestamps" , "Table1"."Millis" )
        

Input

Output

Table1

Timestamps : date

Millis : int

Mon Jan 01 2018 00:00:00.000

1000

Mon Jan 01 2018 00:00:00.000

0

Mon Jan 01 2018 00:00:00.000

-1000

Result

Column1 : date

Mon Jan 01 2018 00:00:01.000

Mon Jan 01 2018 00:00:00.000

Sun Dec 31 2017 23:59:59.000

[2]

A simple ADD_MILLIS example using a weekday calendar. The first of January 2018 is a Monday.

Query

Column1

         ADD_MILLIS ( "TimestampTable"."Timestamps" , "TimestampTable"."Millis" , WEEKDAY_CALENDAR ( MONDAY 09:00 - 17:00 TUESDAY 09:00 - 17:00 THURSDAY 09:00 - 17:00 FRIDAY 09:00 - 17:00 SATURDAY 09:00 - 17:00 ) )
        

Input

Output

TimestampTable

Timestamps : date

Millis : int

Mon Jan 01 2018 10:00:00.000

1111

Tue Jan 02 2018 09:00:00.000

-5

Result

Column1 : date

Mon Jan 01 2018 10:00:01.111

Mon Jan 01 2018 16:59:59.995

[3]

If the start timestamp is not covered by the given calendar, adding 0 milliseconds returns the first timestamp after the start that is covered by the calendar.

Query

Column1

         ADD_MILLIS ( "TimestampTable"."Timestamps" , "TimestampTable"."Millis" , WEEKDAY_CALENDAR ( MONDAY 09:00 - 17:00 TUESDAY 09:00 - 17:00 THURSDAY 09:00 - 17:00 FRIDAY 09:00 - 17:00 SATURDAY 09:00 - 17:00 ) )
        

Input

Output

TimestampTable

Timestamps : date

Millis : int

Mon Jan 01 2018 05:00:00.000

0

Mon Jan 01 2018 09:00:00.000

0

Result

Column1 : date

Mon Jan 01 2018 09:00:00.000

Mon Jan 01 2018 09:00:00.000

[4]

ADD_MILLIS can also be used with an intersection of different calendars. Only the timestamps that are covered by both calendars are taken into account.

Query

Column1

         ADD_MILLIS ( "TimestampTable"."Timestamps" , "TimestampTable"."Millis" , INTERSECT ( WEEKDAY_CALENDAR ( MONDAY 09:00 - 17:00 TUESDAY 09:00 - 17:00 WEDNESDAY 09:00 - 17:00 THURSDAY 09:00 - 17:00 FRIDAY 09:00 - 17:00 ) , FACTORY_CALENDAR ( "FactoryTable"."START" , "FactoryTable"."END" ) ) )
        

Input

Output

FactoryTable

START : date

END : date

Tue Jan 02 2018 09:00:00.000

Tue Jan 02 2018 12:00:00.000

Tue Jan 02 2018 13:00:00.000

Tue Jan 02 2018 16:00:00.000

Wed Jan 03 2018 09:00:00.000

Wed Jan 03 2018 12:00:00.000

Wed Jan 03 2018 13:00:00.000

Wed Jan 03 2018 16:00:00.000

TimestampTable

Timestamps : date

Millis : int

Tue Jan 02 2018 11:59:59.900

100

Wed Jan 03 2018 09:00:00.010

-20

Result

Column1 : date

Tue Jan 02 2018 13:00:00.000

Tue Jan 02 2018 15:59:59.990

[5]

It is also possible to use different calendars for different rows by specifying an additional calendar id column.

Query

Column1

         ADD_MILLIS ( "TimestampTable"."Timestamps" , "TimestampTable"."Millis" , FACTORY_CALENDAR ( "FactoryTable" ) , "TimestampTable"."Ident" )
        

Input

Output

FactoryTable

IDENT : string

START : date

END : date

'DE'

Tue Jan 02 2018 08:00:00.000

Tue Jan 02 2018 17:00:00.000

'US'

Tue Jan 02 2018 14:00:00.000

Tue Jan 02 2018 23:00:00.000

TimestampTable

IDENT : string

Timestamps : date

Millis : int

'DE'

Tue Jan 02 2018 00:00:00.000

1001

'US'

Tue Jan 02 2018 00:00:00.000

1002

Result

Column1 : date

Tue Jan 02 2018 08:00:01.001

Tue Jan 02 2018 14:00:01.002