Top Description Fields Constructors Methods
org.h2.expression.function

public final Class DateTimeFunction

extends Function1_2
Class Inheritance
Imports
org.h2.mvstore.db.Store, java.math.BigDecimal, .BigInteger, java.time.temporal.WeekFields, java.util.Locale, org.h2.api.IntervalQualifier, org.h2.engine.Mode.ModeEnum, .SessionLocal, org.h2.expression.Expression, .TypedValueExpression, org.h2.message.DbException, org.h2.util.DateTimeUtils, .IntervalUtils, .MathUtils, .StringUtils, org.h2.value.DataType, .TypeInfo, .Value, .ValueBigint, .ValueDate, .ValueInteger, .ValueInterval, .ValueNumeric, .ValueTime, .ValueTimeTimeZone, .ValueTimestamp, .ValueTimestampTimeZone

A date-time function.

Field Summary

Modifier and TypeField and Description
private static final BigDecimal
private static final BigDecimal
private static final BigInteger
public static final int
CENTURY

Century.

public static final int
DATE_TRUNC

DATE_TRUNC() (non-standard).

public static final int
DATEADD

DATEADD() (non-standard).

public static final int
DATEDIFF

DATEDIFF() (non-standard).

public static final int
DAY

Day of month.

public static final int
DAY_OF_WEEK

Day of week (locale-specific).

public static final int
DAY_OF_YEAR

Day of year.

public static final int
DECADE

Decade.

public static final int
DOW

Day of week (locale-specific) for PostgreSQL compatibility.

public static final int
EPOCH

Epoch.

public static final int
EXTRACT

EXTRACT().

private final int
private static final String[]
private static final int
private final int
public static final int
HOUR

Hour.

public static final int
ISO_DAY_OF_WEEK

ISO day of week.

public static final int
ISO_WEEK

ISO week.

public static final int
ISO_WEEK_YEAR

ISO week-based year.

public static final int
LAST_DAY

LAST_DAY() (non-standard);

public static final int
MICROSECOND

Microsecond.

public static final int
MILLENNIUM

Millennium.

public static final int
MILLISECOND

Millisecond.

public static final int
MINUTE

Minute.

public static final int
MONTH

Month.

private static final String[]
public static final int
NANOSECOND

Nanosecond.

public static final int
QUARTER

Quarter.

public static final int
SECOND

Second.

public static final int
TIMEZONE_HOUR

Time zone hour.

public static final int
TIMEZONE_MINUTE

Time zone minute.

public static final int
TIMEZONE_SECOND

Time zone second.

public static final int
WEEK

Week (locale-specific).

private static volatile WeekFields
WEEK_FIELDS

Local definitions of day-of-week, week-of-month, and week-of-year.

public static final int
WEEK_YEAR

Week-based year (locale-specific).

public static final int
YEAR

Year.

Constructor Summary

AccessConstructor and Description
public
DateTimeFunction(int function, int field, Expression arg1, Expression arg2)

Method Summary

Modifier and TypeMethod and Description
private static Value
addToTimeZone(int field, long count, Value v, int type, long dateValue, long timeNanos)

private static Value
addYearsMonths(int field, boolean years, long count, Value v, int type, long dateValue, long timeNanos)

private static int
century(int year)

public static Value

Returns:

result
dateadd
(SessionLocal
the session
session
,
int
the date-time field
field
,
long
count to add
count
,
Value
value to add to
v
)

DATEADD function.

private static long

Returns:

the number of crossed boundaries
datediff
(SessionLocal
the session
session
,
int
the date-time field
field
,
Value
the first date-time value
v1
,
Value
the second date-time value
v2
)

Calculate the number of crossed unit boundaries between two timestamps.

private static int
decade(int year)

pack-priv static int
extractDateTime(SessionLocal session, Value date, int field)

private static ValueNumeric
private static int

Returns:

the value
extractInteger
(SessionLocal
the session
session
,
Value
the date value
date
,
int
the field type
field
)

Get the specified field of a date, however with years normalized to positive or negative, and month starting with 1.

private static int
extractInterval(Value date, int field)

public static int

Returns:

the date-time field
getField
(String
the name
name
)

Get date-time field for the specified name.

public static String

Returns:

the name of the specified field
getFieldName
(int
the date-time field
field
)

Get the name of the specified date-time field.

private static int
getLocalDayOfWeek(long dateValue)

private static int
getLocalWeekOfYear(long dateValue)

public String
public StringBuilder
getUnenclosedSQL(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
)

Overrides org.h2.expression.function.Function1_2.getUnenclosedSQL.

Get the SQL statement of this expression.

public Value
getValue(SessionLocal
the session
session
,
Value
the value of first argument
v1
,
Value
the value of second argument, or null
v2
)

Overrides org.h2.expression.function.Function1_2.getValue.

Returns the value of this function.

private static WeekFields
private static Value
private static int
millennium(int year)

public Expression
optimize(SessionLocal
the session
session
)

Implements abstract org.h2.expression.Expression.optimize.

Try to optimize the expression.

private static Value

Returns:

date the truncated value
truncateDate
(SessionLocal
the session
session
,
int
the date-time field
field
,
Value
the date-time value
value
)

Truncate the given date-time value to the specified field.

private static long
truncateToWeek(long dateValue, int firstDayOfWeek)

private static long
truncateToWeekYear(long dateValue, int firstDayOfWeek, int minimalDaysInFirstWeek)

private static long
weekdiff(long absolute1, long absolute2, int firstDayOfWeek)

Inherited from org.h2.expression.function.Function1_2:
getValue

Field Detail

BD_NANOS_PER_SECONDback to summary
private static final BigDecimal BD_NANOS_PER_SECOND
BD_SECONDS_PER_DAYback to summary
private static final BigDecimal BD_SECONDS_PER_DAY
BI_SECONDS_PER_DAYback to summary
private static final BigInteger BI_SECONDS_PER_DAY
CENTURYback to summary
public static final int CENTURY

Century.

DATE_TRUNCback to summary
public static final int DATE_TRUNC

DATE_TRUNC() (non-standard).

DATEADDback to summary
public static final int DATEADD

DATEADD() (non-standard).

DATEDIFFback to summary
public static final int DATEDIFF

DATEDIFF() (non-standard).

DAYback to summary
public static final int DAY

Day of month.

DAY_OF_WEEKback to summary
public static final int DAY_OF_WEEK

Day of week (locale-specific).

DAY_OF_YEARback to summary
public static final int DAY_OF_YEAR

Day of year.

DECADEback to summary
public static final int DECADE

Decade.

DOWback to summary
public static final int DOW

Day of week (locale-specific) for PostgreSQL compatibility.

EPOCHback to summary
public static final int EPOCH

Epoch.

EXTRACTback to summary
public static final int EXTRACT

EXTRACT().

fieldback to summary
private final int field
FIELD_NAMESback to summary
private static final String[] FIELD_NAMES
FIELDS_COUNTback to summary
private static final int FIELDS_COUNT
functionback to summary
private final int function
HOURback to summary
public static final int HOUR

Hour.

ISO_DAY_OF_WEEKback to summary
public static final int ISO_DAY_OF_WEEK

ISO day of week.

ISO_WEEKback to summary
public static final int ISO_WEEK

ISO week.

ISO_WEEK_YEARback to summary
public static final int ISO_WEEK_YEAR

ISO week-based year.

LAST_DAYback to summary
public static final int LAST_DAY

LAST_DAY() (non-standard);

MICROSECONDback to summary
public static final int MICROSECOND

Microsecond.

MILLENNIUMback to summary
public static final int MILLENNIUM

Millennium.

MILLISECONDback to summary
public static final int MILLISECOND

Millisecond.

MINUTEback to summary
public static final int MINUTE

Minute.

MONTHback to summary
public static final int MONTH

Month.

NAMESback to summary
private static final String[] NAMES
NANOSECONDback to summary
public static final int NANOSECOND

Nanosecond.

QUARTERback to summary
public static final int QUARTER

Quarter.

SECONDback to summary
public static final int SECOND

Second.

TIMEZONE_HOURback to summary
public static final int TIMEZONE_HOUR

Time zone hour.

TIMEZONE_MINUTEback to summary
public static final int TIMEZONE_MINUTE

Time zone minute.

TIMEZONE_SECONDback to summary
public static final int TIMEZONE_SECOND

Time zone second.

WEEKback to summary
public static final int WEEK

Week (locale-specific).

WEEK_FIELDSback to summary
private static volatile WeekFields WEEK_FIELDS

Local definitions of day-of-week, week-of-month, and week-of-year.

WEEK_YEARback to summary
public static final int WEEK_YEAR

Week-based year (locale-specific).

YEARback to summary
public static final int YEAR

Year.

Constructor Detail

DateTimeFunctionback to summary
public DateTimeFunction(int function, int field, Expression arg1, Expression arg2)

Method Detail

addToTimeZoneback to summary
private static Value addToTimeZone(int field, long count, Value v, int type, long dateValue, long timeNanos)
addYearsMonthsback to summary
private static Value addYearsMonths(int field, boolean years, long count, Value v, int type, long dateValue, long timeNanos)
centuryback to summary
private static int century(int year)
dateaddback to summary
public static Value dateadd(SessionLocal session, int field, long count, Value v)

DATEADD function.

Parameters
session:SessionLocal

the session

field:int

the date-time field

count:long

count to add

v:Value

value to add to

Returns:Value

result

datediffback to summary
private static long datediff(SessionLocal session, int field, Value v1, Value v2)

Calculate the number of crossed unit boundaries between two timestamps. This method is supported for MS SQL Server compatibility.

DATEDIFF(YEAR, '2004-12-31', '2005-01-01') = 1
Parameters
session:SessionLocal

the session

field:int

the date-time field

v1:Value

the first date-time value

v2:Value

the second date-time value

Returns:long

the number of crossed boundaries

decadeback to summary
private static int decade(int year)
extractDateTimeback to summary
pack-priv static int extractDateTime(SessionLocal session, Value date, int field)
extractEpochback to summary
private static ValueNumeric extractEpoch(SessionLocal session, Value value)
extractIntegerback to summary
private static int extractInteger(SessionLocal session, Value date, int field)

Get the specified field of a date, however with years normalized to positive or negative, and month starting with 1.

Parameters
session:SessionLocal

the session

date:Value

the date value

field:int

the field type

Returns:int

the value

extractIntervalback to summary
private static int extractInterval(Value date, int field)
getFieldback to summary
public static int getField(String name)

Get date-time field for the specified name.

Parameters
name:String

the name

Returns:int

the date-time field

Exceptions
DbException:
on unknown field name
getFieldNameback to summary
public static String getFieldName(int field)

Get the name of the specified date-time field.

Parameters
field:int

the date-time field

Returns:String

the name of the specified field

getLocalDayOfWeekback to summary
private static int getLocalDayOfWeek(long dateValue)
getLocalWeekOfYearback to summary
private static int getLocalWeekOfYear(long dateValue)
getNameback to summary
public String getName()

Implements org.h2.expression.function.NamedExpression.getName.

Doc from org.h2.expression.function.NamedExpression.getName.

Get the name.

Returns:String

the name in uppercase

Annotations
@Override
getUnenclosedSQLback to summary
public StringBuilder getUnenclosedSQL(StringBuilder builder, int sqlFlags)

Overrides org.h2.expression.function.Function1_2.getUnenclosedSQL.

Doc from org.h2.expression.Expression.getUnenclosedSQL.

Get the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization. Enclosing '(' and ')' are never appended.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

Annotations
@Override
getValueback to summary
public Value getValue(SessionLocal session, Value v1, Value v2)

Overrides org.h2.expression.function.Function1_2.getValue.

Doc from org.h2.expression.function.Function1_2.getValue.

Returns the value of this function.

Parameters
session:SessionLocal

the session

v1:Value

the value of first argument

v2:Value

the value of second argument, or null

Returns:Value

the resulting value

Annotations
@Override
getWeekFieldsback to summary
private static WeekFields getWeekFields()
lastDayback to summary
private static Value lastDay(SessionLocal session, Value v)
millenniumback to summary
private static int millennium(int year)
optimizeback to summary
public Expression optimize(SessionLocal session)

Implements abstract org.h2.expression.Expression.optimize.

Doc from org.h2.expression.Expression.optimize.

Try to optimize the expression.

Parameters
session:SessionLocal

the session

Returns:Expression

the optimized expression

Annotations
@Override
truncateDateback to summary
private static Value truncateDate(SessionLocal session, int field, Value value)

Truncate the given date-time value to the specified field.

Parameters
session:SessionLocal

the session

field:int

the date-time field

value:Value

the date-time value

Returns:Value

date the truncated value

truncateToWeekback to summary
private static long truncateToWeek(long dateValue, int firstDayOfWeek)
truncateToWeekYearback to summary
private static long truncateToWeekYear(long dateValue, int firstDayOfWeek, int minimalDaysInFirstWeek)
weekdiffback to summary
private static long weekdiff(long absolute1, long absolute2, int firstDayOfWeek)