Skip to content

Date Functions

add_day

Syntaxadd_day(T,I)
Parameters1. Time type parameter;
2. Number of days to add, optional type: number
Return TypeTime
DescriptionReturns the date after the specified number of days from the starting date. If the numeric field is negative, it returns the date before the specified number of days.
Exampleadd_day('2018-02-02', 3), returns: 2018-02-05

add_hour

Syntaxadd_hour(T,I)
Parameters1. Time type parameter;
2. Number of hours to add, optional type: numeric
Return TypeTime
DescriptionReturns the time after adding the specified number of hours to the starting time. If the numeric field is negative, it returns the time before the specified number of hours.
Exampleadd_hour('2018-02-02 08:30:00.000', 3), returns: 2018-02-02 11:30:00.000

add_minute

Syntaxadd_minute(T,I)
Parameters1. Time type parameter;
2. Minutes to add, optional type: number
Return TypeTime
DescriptionReturns the time after adding the specified number of minutes to the starting time. If the numeric field is negative, it returns the time before the specified number of minutes.
Exampleadd_minute('2018-02-02 08:30:00.000', 3), returns: 2018-02-02 08:33:00.000

add_month

Syntaxadd_month(T,I)
Parameters1. Time type parameter;
2. Number of months to add, optional type: number
Return TypeTime
DescriptionReturns the date after the specified number of months from the starting date. If the numeric field is negative, it returns the date before the specified number of months.
Exampleadd_month('2018-02-02', 3), returns: 2018-05-02

add_quarter

Syntaxadd_quarter(T,I)
Parameters1. Time type parameter;
2. Number of quarters to add, optional type: number
Return TypeTime
DescriptionReturns the date after the specified number of quarters from the start date. If the numeric field is negative, it returns the date before the specified number of quarters.
Exampleadd_quarter('2018-02-02', 3), returns: 2018-05-02

add_week

Syntaxadd_week(T,I)
Parameters1. Time type parameter;
2. Number of weeks to add, optional type: number
Return TypeTime
DescriptionReturns the date after the specified number of weeks from the start date. If the numeric field is negative, it returns the date before the specified number of weeks.
Exampleadd_week('2018-02-02', 3), returns: 2018-05-02

add_year

Syntaxadd_year(T,I)
Parameters1. Time type parameter;
2. Number of years to add, optional type: number
Return TypeTime
DescriptionReturns the date after the specified number of years from the starting date. If the numeric field is negative, it returns the date before the specified number of years.
Exampleadd_year('2018-02-02', 3), returns: 2021-02-02

add_year_keep_woy

Syntaxadd_year_keep_woy(T,I)
Parameter Description1. Time type parameter;
2. Number of years to add, optional type: number
Return TypeTime
DescriptionSimilar to add_year, but adjusts the date to keep the week of the year unchanged
Exampleadd_year_keep_woy('2023-01-01', 1), returns: 2024-01-01 (example, specific result may vary depending on week calculation logic)
Unsupported Data Sourcesmysql, tidb, sqlserver, redshift, spark, hive, impala, presto, db2, mongodb, maxcompute

age_in_days

Syntaxage_in_days(START, END)
Parameters1. Start time, time-type parameter;
2. End time, time-type parameter
Return TypeNumber
DescriptionCompares the difference in days between two times, with all time components involved in the calculation.
Exampleage_in_days('2021-05-31 00:00:50', '2022-05-31 00:00:00'), returns: 364

age_in_hours

Syntaxage_in_hours(START, END)
Parameters1. Start time, time type parameter;
2. End time, time type parameter
Return TypeNumber
DescriptionCompares the difference between two times in hours, with all time components included in the calculation.
Exampleage_in_hours('2021-05-31 00:00:50', '2022-05-31 00:00:00'), returns: 8759

age_in_milliseconds

Syntaxage_in_milliseconds(START, END)
Parameter Description1. Start time, time type parameter;
2. End time, time type parameter
Return TypeNumber
DescriptionCompares the difference in milliseconds between two times, with all time components included in the calculation.
Exampleage_in_milliseconds('2021-05-31 00:00:00.531', '2022-05-31 00:00:00.000'), returns: 31535999469

age_in_minutes

Syntaxage_in_minutes(START, END)
Parameter Description1. Start time, time-type parameter;
2. End time, time-type parameter
Return TypeNumber
DescriptionCompares the difference between two times in minutes, with all time components involved in the calculation.
Exampleage_in_minutes('2021-05-31 00:00:50', '2022-05-31 00:00:00'), returns: 525599

age_in_months

Syntaxage_in_months(START, END)
Parameter Description1. Start time, time type parameter;
2. End time, time type parameter
Return TypeNumber
DescriptionCompares the difference in months between two times, with all time components participating in the calculation.
Exampleage_in_months('2021-05-31 00:00:50', '2022-05-31 00:00:00'), returns: 11

age_in_seconds

Syntaxage_in_seconds(START, END)
Parameter Description1. Start time, time type parameter;
2. End time, time type parameter
Return TypeNumber
DescriptionCompares the difference between two times in seconds, with all time components included in the calculation.
Exampleage_in_seconds('2021-05-31 00:00:00.531', '2022-05-31 00:00:00.000'), returns: 31535999

age_in_years

Syntaxage_in_years(START, END)
Parameter Description1. Start time, time-type parameter;
2. End time, time-type parameter
Return TypeNumber
DescriptionCompares the difference in years between two times, with all time components participating in the calculation.
Exampleage_in_years('2021-05-31 00:00:50', '2022-05-31 00:00:00'), returns: 0

diff_in_day

Syntaxdiff_in_day(START,END)
Parameter Description1. Specify the start, optional type: time;
2. Specify the end, optional type: time
Return Value TypeNumber
DescriptionCompares the difference in days between two dates.
Examplediff_in_day('2015-02-03', '2018-02-03'), returns: 1095

diff_in_hour

Syntaxdiff_in_hour(START,END)
Parameter Description1. Specify the start time, optional type: time;
2. Specify the end time, optional type: time
Return TypeNumber
DescriptionCompares the difference between two times in hours.
Examplediff_in_hour('2015-03-24 16:32:32', '2018-02-02 12:34:43'), returns: 25100

diff_in_minute

Syntaxdiff_in_minute(START,END)
Parameter Description1. Specify the start time, optional type: time;
2. Specify the end time, optional type: time
Return TypeNumber
DescriptionCompares the difference between two times in minutes.
Examplediff_in_minute('2015-03-24 16:32:32', '2018-02-02 12:34:43'), returns: 1506002

diff_in_month

Syntaxdiff_in_month(START,END)
Parameter Description1. Specify the start, optional type: time;
2. Specify the end, optional type: time
Return TypeNumber
DescriptionCompares the difference in months between two dates.
Examplediff_in_month('2015-02-03', '2018-02-03'), returns: 36

diff_in_year

Syntaxdiff_in_year(START,END)
Parameter Description1. Specify the start, optional type: time;
2. Specify the end, optional type: time
Return TypeNumber
DescriptionCompares the difference in years between two times.
Examplediff_in_year('2015-02-03', '2018-02-03'), returns: 3

end_of_month

Syntaxend_of_month(T)
ParameterTime type parameter
Return TypeTime
DescriptionRetrieves the start time of the last day of the month for the given time field
Exampleend_of_month('2018-02-02'), returns: 2018-02-28

extract_day

Syntaxextract_day(T)
ParameterTime type parameter
Return TypeNumber
DescriptionRetrieves the day part of the parameter, indicating which day of the month it is.
Exampleextract_day('2018-02-02'), returns: 2

extract_dow

Syntaxextract_dow(T)
Parameter DescriptionTime-type parameter
Return Value TypeNumber
DescriptionRetrieves the day part of the parameter, indicating which day of the week it is.
Exampleextract_dow('2018-02-02'), returns: 5

extract_doy

Syntaxextract_doy(T)
ParameterTime type parameter
Return TypeNumber
DescriptionRetrieves the day part of the parameter, indicating which day of the year it is.
Exampleextract_doy('2018-02-02'), returns: 33

extract_hour

Syntaxextract_hour(T)
Parameter DescriptionTime-type parameter
Return Value TypeNumber
DescriptionRetrieves the hour part from the parameter, representing the current hour.
Exampleextract_hour('2018-02-03 13:23:21'), returns: 13

extract_minute

Syntaxextract_minute(T)
ParameterTime type parameter
Return TypeNumber
DescriptionRetrieves the minute part of the parameter, representing the current minute.
Exampleextract_minute('2018-02-03 13:23:21'), returns: 23

extract_month

Syntaxextract_month(T)
ParameterTime type parameter
Return TypeNumber
DescriptionRetrieves the month part from the parameter.
Exampleextract_month('2018-02-02'), returns: 2

extract_quarter

Syntaxextract_quarter(T)
ParameterTime type parameter
Return TypeNumber
DescriptionRetrieves the quarter part from the parameter.
Exampleextract_quarter('2018-02-02'), returns: 1

extract_second

Syntaxextract_second(T)
ParameterTime type parameter
Return TypeNumber
DescriptionRetrieves the second part of the parameter, representing the current second.
Exampleextract_second('2018-02-03 13:23:21'), returns: 21

extract_week

Syntaxextract_week(T)
ParameterTime type parameter
Return TypeNumber
DescriptionRetrieves the week part of the parameter, indicating which week of the year the given day belongs to.
Exampleextract_week('2018-02-02'), returns: 4

extract_year

Syntaxextract_year(T)
ParameterTime type parameter
Return TypeNumber
DescriptionRetrieves the year part from the parameter.
Exampleextract_year('2018-02-02'), returns: 2018

month_weekday_count

Syntaxmonth_weekday_count(YEAR,MONTH)
Parameter Description1. Year, optional type: number;
2. Month, optional type: number
Return Value TypeNumber
DescriptionRetrieves the number of weekdays in the specified month.
Examplemonth_weekday_count(2018, 2), returns: 20
Unsupported Data Sourcesmysql, tidb, sqlserver, redshift, oracle, impala, hive, spark, db2, mongodb, maxcompute

now

Syntaxnow()
ParametersNone
Return TypeTime
DescriptionReturns the current time, including hour, minute, and second information.
Examplenow(), returns: current system time (e.g., 2024-05-20 15:30:45)

parse_time

Syntaxparse_time(S,LITERAL_PATTERN)
Parameter Description1. Text type parameter;
2. Specified pattern, optional type: string
Return Value TypeTime
DescriptionParses the s parameter into a time type using literal_pattern
Exampleparse_time('2024-05-20', 'yyyy-MM-dd'), returns: 2024-05-20
Unsupported Data Sourcesqlserver

time_in_range

Syntaxtime_in_range(T,S)
Parameter Description1. Time type parameter;
2. Text type parameter
Return TypeBoolean
DescriptionDetermines whether the date is within the specified range. Available ranges include: 'Current Year', 'Current Year-to-Date', 'Current Quarter', 'Current Quarter-to-Date', 'Current Month', 'Current Month-to-Date', 'Current Week', 'Current Week-to-Date', 'Today', 'Current Hour', 'Yesterday', 'Recent 7 days', 'Recent 30 days', 'Recent 90 days', 'All Available Date', 'All Invalid Date', 'All'
Exampletime_in_range('2024-05-20', 'Today'), returns: TRUE (if the current date is 2024-05-20)

today

Syntaxtoday()
ParameterNone
Return TypeDate
DescriptionReturns the current date, excluding hour, minute, and second information.
Exampletoday(), returns: the current system date (e.g., 2024-05-20)

trunc_day

Syntaxtrunc_day(T)
ParameterTime type parameter
Return TypeTime
DescriptionTruncates the time or date column to the day.
Exampletrunc_day('2018-02-02 12:30:59'), returns: '2018-02-02'

trunc_hour

Syntaxtrunc_hour(T)
ParameterTime type parameter
Return TypeTime
DescriptionTruncates the time column to the hour, setting finer granularity to 0.
Exampletrunc_hour('2018-02-02 12:23:32'), returns: '2018-02-02 12:00:00'

trunc_minute

Syntaxtrunc_minute(T)
Parameter DescriptionTime type parameter
Return Value TypeTime
DescriptionTruncates the time column to minutes, setting all finer granularity to 0.
Exampletrunc_minute('2018-02-02 12:23:32'), returns: '2018-02-02 12:23:00'

trunc_month

Syntaxtrunc_month(T)
Parameter DescriptionTime type parameter
Return Value TypeTime
DescriptionTruncates the time or date column to the month, setting the date to the 1st day of the month.
Exampletrunc_month('2018-02-02 12:23:32'), returns: '2018-02-01'

trunc_millisecond

Syntaxtrunc_millisecond(T)
ParameterTime type parameter
Return TypeTime
DescriptionTruncates the time column to milliseconds, setting all finer granularity to 0.
Exampletrunc_millisecond('2018-02-02 12:23:32.123'), returns: '2018-02-02 12:23:32.123'

trunc_quarter

Syntaxtrunc_quarter(T)
Parameter DescriptionTime type parameter
Return Value TypeTime
DescriptionTruncates the time or date column to the quarter, sets the month to the first month of the quarter, and the date to the 1st.
Exampletrunc_quarter('2018-05-02 12:23:32'), returns: '2018-04-01'

trunc_second

Syntaxtrunc_second(T)
Parameter DescriptionTime type parameter
Return Value TypeTime
DescriptionTruncates the time column to seconds, setting all finer granularity to 0.
Exampletrunc_second('2018-02-02 12:23:32.123'), returns: '2018-02-02 12:23:32.000'

trunc_week

Syntaxtrunc_week(T)
ParameterTime type parameter
Return TypeTime
DescriptionTruncates the time or date column to the week, setting the month and date to the first day of the week.
Exampletrunc_week('2018-02-02'), returns: '2018-01-29'

trunc_year

Syntaxtrunc_year(T)
Parameter DescriptionTime type parameter
Return Value TypeTime
DescriptionTruncates the time or date column to the year, setting the month and day to January 1st.
Exampletrunc_year('2018-02-02 12:23:32'), returns: '2018-01-01'

User Manual for Hengshi Analysis Platform