This extension provides time related functionality to Siddhi such as getting the current time, current date, manipulating/formatting dates, etc. Following are the functions of the time extension.
Current Date function
Syntax | <string> time:currentDate ( ) |
---|
Extension Type | Function |
---|
Description | Returns the current system date in the yyyy-MM-dd  format. |
---|
Example | currentDate()  returns 2015-08-20 . |
---|
Â
Current Time function
Syntax | <string> currentTime ( ) |
---|
Extension Type | Function |
---|
Description | Returns the current system time in the HH:mm:ss  format. |
---|
Example | currentTime()  returns 13:15:10 . |
---|
Â
Current Timestamp function
Syntax | <string>Â time:
currentTimestamp ( ) |
---|
Extension Type | Function |
---|
Description | Returns the current system timestamp in the yyyy-MM-dd HH:mm:ss  format. |
---|
Example | currentTimestamp()  returns 2015-08-20 13:15:10 . |
---|
Date Adding function
The common parameters of this function are described below.
-
dateValue
: A value of date. e.g., "2014-11-11 13:23:44.657"
, "2014-11-11"
, "13:23:44.657"
-
expr
:Â The amount by which the selected part of the date format should be incremented. e.g., 2 ,5 ,10 etc. -
unit
: The part of the date format that needs to be manipulated. e.g., "MINUTE"
 , "HOUR"
 , "MONTH"
 , "YEAR"
 , "QUARTER"
 , * "WEEK"
 , "DAY"
 , "SECOND"
-
dateFormat
: The date format of the date value provided. e.g., yyyy-MM-dd HH:mm:ss.SSS
-
timestampInMilliseconds
: The date value in milliseconds (from the epoch). e.g., 1415712224000L
Syntax | <string>Â time:
dateAdd (<string> dateValue , <long> expr, <string> unit, <string> dateFormat ) |
---|
Extension Type | Function |
---|
Description | Returns the specified date and time with the selectedÂ
unitÂ
of the specifiedÂ
dateValue
 incremented by the given amount (i.e. expr ). |
---|
Example | dateAdd("2014-11-11 13:23:44", 2, 'year',"yyyy-MM-dd HH:mm:ss")  returns "2016-11-11 13:23:44" . |
---|
Syntax | <string>Â time:
dateAdd (<string>  dateValue  , < long >  expr,  <string>  unit ) |
---|
Extension Type | Function |
---|
Description | Returns the specified date and time with the selectedÂ
unit
 of the specifiedÂ
dateValue
 incremented by the given amount (i.e. expr ). |
---|
Example | dateAdd("2014-11-11 13:23:44", 2, 'year')  returns "2016-11-11 13:23:44" . |
---|
Syntax | <string>Â time:
dateAdd (<long>  timestampInMilliseconds, < long >   expr,  <string>  unit ) |
---|
Extension Type | Function |
---|
Description | Returns the specified time stamp with the selectedÂ
unit
 of the specifiedÂ
timestampInMilliseconds
 incremented by the given amount (i.e. expr ). |
---|
Example | dateAdd(1415692424000L, 2, 'year')  returns "2016-11-11 13:23:44" . |
---|
Date Subtraction function
The common parameters of this function are described below.
-
dateValue
: A value of date. e.g., "2014-11-11 13:23:44.657"
, "2014-11-11"
, "13:23:44.657"
-
expr
:Â The amount by which the selected part of the date format should be reduced. e.g., 2 ,5 ,10 etc. -
unit
: The part of the date format that needs to be manipulated. e.g., "MINUTE"
 , "HOUR"
 , "MONTH"
 , "YEAR"
 , "QUARTER"
 , * "WEEK"
 , "DAY"
 , "SECOND"
-
dateFormat
: The date format of the date value provided. e.g., yyyy-MM-dd HH:mm:ss.SSS
-
timestampInMilliseconds
: The date value in milliseconds (from the epoch). e.g., 1415712224000L
Syntax | <string>Â time:
dateSub (<string> dateValue , <long> expr, <string> unit, <string> dateFormat ) |
---|
Extension Type | Function |
---|
Description | Returns the specified date and time with the selectedÂ
unitÂ
of the specifiedÂ
dateValue
 reduced by the given amount (i.e. expr ). |
---|
Example | dateSub("2014-11-11 13:23:44", 2, 'year',"yyyy-MM-dd HH:mm:ss")  returns "2012-11-11 13:23:44" . |
---|
Syntax | <string>Â time:
dateSub (<string>  dateValue  , < long >  expr,  <string>  unit ) |
---|
Extension Type | Function |
---|
Description | Returns the specified date and time stamp with he selectedÂ
unit
 of the specifiedÂ
dateValue
 reduced by the given amount (i.e. expr ). |
---|
Example | dateSub("2014-11-11 13:23:44", 2, 'year')  returns "2012-11-11 13:23:44". |
---|
Syntax | <string>Â time:
dateSub (<long>  timestampInMilliseconds,  < long >   expr,  <string>  unit ) |
---|
Extension Type | Function |
---|
Description | Returns the specified time stamp with the selectedÂ
unit
 of the specifiedÂ
timestampInMilliseconds
  reduced by the given amount (i.e. expr ). |
---|
Example |  dateSub(1415692424000L, 2, 'year')  returns 1352620424000. |
---|
Date Difference function
The common parameters of this function are described below.
-
dateValue1
: A value of date. e.g., "2014-11-11 13:23:44.657"
, "2014-11-11"
 , "13:23:44.657"
-
dateValue2
: A value of date. e.g., "2014-11-11 13:23:44.657"
, "2014-11-11"
 , "13:23:44.657"
-
dateFormat1
: The date format of dateValue1
. e.g., yyyy-MM-dd HH:mm:ss.SSS
-
dateFormat2
: The date format of dateValue2
. e.g., yyyy-MM-dd HH:mm:ss.SSS
-
timestampInMilliseconds1
: A date value in milliseconds (from the epoch) e.g., 1415712224000L
-
timestampInMilliseconds2
:A date value in milliseconds (from the epoch) e.g., 1415712224000L
Syntax | <int>Â time:
dateDiff (<string> dateValue1 ,  < string >  dateValue2 ,  <string> dateFormat1, <string> dateFormat2 ) |
---|
Extension Type | Function |
---|
Description | Returns the number of days between the two dates specified (i.e. dateValue1  and dateValue2 ). |
---|
Example | dateDiff('2014-11-11 13:23:44', '2014-11-9 13:23:44', 'yyyy-MM-dd HH:mm:ss', 'yyyy-MM-dd HH:mm:ss')  returns 2 . |
---|
Syntax | <int>Â time:
dateDiff (<string> dateValue1 ,  < string >  dateValue2 ) |
---|
Extension Type | Function |
---|
Description | Returns the number of days between the two dates specified (i.e. dateValue1  and dateValue2 ). |
---|
Example | dateDiff('2014-11-11 13:23:44.000', '2014-11-9 13:23:44.000' ) returns 2 . |
---|
Syntax | <int>Â time:
dateDiff (<string> timestampInMilliseconds1 ,  < string >  timestampInMilliseconds2 ) |
---|
Extension Type | Function |
---|
Description | Returns the number of days between the two date and time stamps specified (i.e.Â
timestampInMilliseconds1
 andÂ
timestampInMilliseconds2
). |
---|
Example | dateDiff(1415692424000, 1415519624000)  returns 2 . |
---|
Â
The common parameters of this function are described below.
-
dateValue
: -A value of date. e.g., "2014-11-11 13:23:44.657
", "2014-11-11"
 , "13:23:44.657"Â
-
dateTargetFormat
: The date format to which the specified date value
 needs to be converted. e.g., yyyy/MM/dd HH:mm:ss
-
dateSourceFormat
: The date format of the date value
 provided. e.g., yyyy-MM-dd HH:mm:ss.SSS
-
timestampInMilliseconds
: A date value in milliseconds (from the epoch) e.g., 1415712224000L
Syntax | <string>Â time:
dateFormat(<string>Â Â dateValue,<string>Â Â dateTargetFormat,<string>Â Â dateSourceFormat) |
---|
Extension Type | Function |
---|
Description | Returns a formatted date string. |
---|
Example | dateFormat('2014-11-11 13:23:55', 'ss', 'yyyy-MM-dd HH:mm:ss')  returns 55 . |
---|
Syntax | <string>Â time:
dateFormat(<string>Â Â dateValue,<string>Â Â dateTargetFormat) |
---|
Extension Type | Function |
---|
Description | Returns a formatted date string. |
---|
Example | dateFormat('2014-11-11 13:23:55.657', 'ss')  returns 55 . |
---|
Syntax | <string>Â Â time:
dateFormat (<long> timestampInMilliseconds ,<string>  dateTargetFormat) |
---|
Extension Type | Function |
---|
Description | Returns a formatted date string. |
---|
Example | dateFormat(1415692424000, 'yyyy-MM-dd')  returns 2014-11-11.   |
---|
Â
-
dateValue
: A value of date. e.g., "2014-11-11 13:23:44.657"
, "2014-11-11"
 , "13:23:44.657"Â
-
unit
: The part of the date format that needs to be manipulated. e.g., "MINUTE"
 , "HOUR"
 , "MONTH"
 , "YEAR"
 , "QUARTER"
 , * "WEEK"
 , "DAY"
 , "SECOND"
-
dateFormat
: The date format of the date value provided. e.g., yyyy-MM-dd HH:mm:ss.SSS
-
timestampInMilliseconds
: A date value in milliseconds (from the epoch) e.g., 1415712224000L
Syntax | <int>Â Â time:
extract (<string> unit ,<string>  dateValue, <string> dataFormat) |
---|
Extension Type | Function |
---|
Description | Returns the specifiedÂ
unit
 extracted from the specified dateValue . |
---|
Example | extract('year', '2014-3-11 02:23:44', 'yyyy-MM-dd hh:mm:ss')  returns 2014 . |
---|
Syntax | <int>Â Â time:
extract (<string> unit ,<string>  dateValue) |
---|
Extension Type | Function |
---|
Description | Returns the specifiedÂ
unit
 extracted from the specified dateValue . |
---|
Example | extract('year', '2014-3-11 02:23:44.234')  returns 2014 . |
---|
Syntax | <int>Â Â time:
extract (<long> timestampInMilliseconds ,<string>  unit) |
---|
Extension Type | Function |
---|
Description | Returns the specifiedÂ
unit
 extracted from the specifiedÂ
timestampInMilliseconds
. |
---|
Example | extract(1394484824000, 'year')  returns 2014 . |
---|
Â
Date function
Syntax | <string>Â Â time:
date (<string> dateValue ,<string>  dateFormat) |
---|
Extension Type | Function |
---|
Description | Returns the date component of the dateValue . |
---|
Example | date('2014-11-11 13:23:44', 'yyyy-MM-dd HH:mm:ss')  returns 2014-11-11 . |
---|
Â
Timestamp In Milliseconds function
Syntax | <long>Â Â time:
timestampInMilliseconds () |
---|
Extension Type | Function |
---|
Description | Returns the current time stamp in milliseconds. |
---|
Example | timestampInMilliseconds()  returns 1440160328693 . |
---|
Syntax | <long>Â Â time:
timestampInMilliseconds (<string> dateValue) |
---|
Extension Type | Function |
---|
Description | Returns the time stamp of the specified dateValue  in milliseconds. In order to use this function, the date format of the specified dateValue  should be yyyy-MM-dd HH:mm:ss.SSS
. |
---|
Example | timestampInMilliseconds('2007-11-30 10:30:19.000')  returns 1196398819000 . |
---|
Syntax | <long>Â Â time:
timestampInMilliseconds (<string> dateValue, <string> dateFormat) |
---|
Extension Type | Function |
---|
Description | Returns the time stamp of the specified dateValue  in milliseconds. The date format can be specified in the dateForma t parameter. |
---|
Example | timestampInMilliseconds('2007-11-30 10:30:19', 'yyyy-MM-dd HH:mm:ss')  returns 1196398819000 . |
---|
UTC Timestamp function
Syntax | <string>Â time:
utcTimestamp() |
---|
Extension Type | Function |
---|
Description | Returns the system time in the yyyy-MM-dd HH:mm:ss  date format. |
---|
Example | utcTimestamp()  returns 2015-08-21 12:16:13 . |
---|