Package org.h2.expression.function

# Class DateTimeFunction

java.lang.Object
org.h2.expression.Expression
org.h2.expression.Operation1_2
org.h2.expression.function.Function1_2
org.h2.expression.function.DateTimeFunction

All Implemented Interfaces:
  `NamedExpression`, `HasSQL`, `Typed`

public final class DateTimeFunction extends Function1_2
A date-time function.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`CENTURY`
Century.
`static final int`
`DATE_TRUNC`
DATE_TRUNC() (non-standard).
`static final int`
`DATEADD`
DATEADD() (non-standard).
`static final int`
`DATEDIFF`
DATEDIFF() (non-standard).
`static final int`
`DAY`
Day of month.
`static final int`
`DAY_OF_WEEK`
Day of week (locale-specific).
`static final int`
`DAY_OF_YEAR`
Day of year.
`static final int`
`DECADE`
Decade.
`static final int`
`DOW`
Day of week (locale-specific) for PostgreSQL compatibility.
`static final int`
`EPOCH`
Epoch.
`static final int`
`EXTRACT`
EXTRACT().
`static final int`
`HOUR`
Hour.
`static final int`
`ISO_DAY_OF_WEEK`
ISO day of week.
`static final int`
`ISO_WEEK`
ISO week.
`static final int`
`ISO_WEEK_YEAR`
ISO week-based year.
`static final int`
`LAST_DAY`
LAST_DAY() (non-standard);
`static final int`
`MICROSECOND`
Microsecond.
`static final int`
`MILLENNIUM`
Millennium.
`static final int`
`MILLISECOND`
Millisecond.
`static final int`
`MINUTE`
Minute.
`static final int`
`MONTH`
Month.
`static final int`
`NANOSECOND`
Nanosecond.
`static final int`
`QUARTER`
Quarter.
`static final int`
`SECOND`
Second.
`static final int`
`TIMEZONE_HOUR`
Time zone hour.
`static final int`
`TIMEZONE_MINUTE`
Time zone minute.
`static final int`
`TIMEZONE_SECOND`
Time zone second.
`static final int`
`WEEK`
Week (locale-specific).
`static final int`
`WEEK_YEAR`
Week-based year (locale-specific).
`static final int`
`YEAR`
Year.

### Fields inherited from class org.h2.expression.Operation1_2

`left, right, type`

### Fields inherited from class org.h2.expression.Expression

`AUTO_PARENTHESES, MAP_IN_AGGREGATE, MAP_IN_WINDOW, MAP_INITIAL, WITH_PARENTHESES, WITHOUT_PARENTHESES`

### Fields inherited from interface org.h2.util.HasSQL

`ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS`

## Constructor Summary

Constructors
Constructor
Description
`DateTimeFunction(int function, int field, Expression arg1, Expression arg2)`

## Method Summary

Modifier and Type
Method
Description
`static Value`
`dateadd(SessionLocal session, int field, long count, Value v)`
DATEADD function.
`static int`
`getField(String name)`
Get date-time field for the specified name.
`static String`
`getFieldName(int field)`
Get the name of the specified date-time field.
`String`
`getName()`
Get the name.
`StringBuilder`
`getUnenclosedSQL(StringBuilder builder, int sqlFlags)`
Get the SQL statement of this expression.
`Value`
`getValue(SessionLocal session, Value v1, Value v2)`
Returns the value of this function.
`Expression`
`optimize(SessionLocal session)`
Try to optimize the expression.

### Methods inherited from class org.h2.expression.function.Function1_2

`getValue`

### Methods inherited from class org.h2.expression.Operation1_2

`getCost, getSubexpression, getSubexpressionCount, getType, isEverything, mapColumns, setEvaluatable, updateAggregate`

### Methods inherited from class org.h2.expression.Expression

`addFilterConditions, createIndexConditions, getAlias, getBooleanValue, getColumnName, getColumnNameForView, getEnclosedSQL, getNonAliasExpression, getNotIfPossible, getNullable, getSchemaName, getSQL, getSQL, getSQL, getSQL, getTableAlias, getTableName, getTypeIfStaticallyKnown, getWhenSQL, getWhenValue, isConstant, isIdentity, isNullConstant, isValueSet, isWhenConditionOperand, needParentheses, optimizeCondition, toString, writeExpressions, writeExpressions`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.h2.util.HasSQL

`getTraceSQL`

## Field Details

### EXTRACT

public static final int EXTRACT
EXTRACT().

See Also:
  - Constant Field Values

### DATE_TRUNC

public static final int DATE_TRUNC
DATE_TRUNC() (non-standard).

See Also:
  - Constant Field Values

### DATEADD

public static final int DATEADD
DATEADD() (non-standard).

See Also:
  - Constant Field Values

### DATEDIFF

public static final int DATEDIFF
DATEDIFF() (non-standard).

See Also:
  - Constant Field Values

### LAST_DAY

public static final int LAST_DAY
LAST_DAY() (non-standard);

See Also:
  - Constant Field Values

### YEAR

public static final int YEAR
Year.

See Also:
  - Constant Field Values

### MONTH

public static final int MONTH
Month.

See Also:
  - Constant Field Values

### DAY

public static final int DAY
Day of month.

See Also:
  - Constant Field Values

### HOUR

public static final int HOUR
Hour.

See Also:
  - Constant Field Values

### MINUTE

public static final int MINUTE
Minute.

See Also:
  - Constant Field Values

### SECOND

public static final int SECOND
Second.

See Also:
  - Constant Field Values

### TIMEZONE_HOUR

public static final int TIMEZONE_HOUR
Time zone hour.

See Also:
  - Constant Field Values

### TIMEZONE_MINUTE

public static final int TIMEZONE_MINUTE
Time zone minute.

See Also:
  - Constant Field Values

### TIMEZONE_SECOND

public static final int TIMEZONE_SECOND
Time zone second.

See Also:
  - Constant Field Values

### MILLENNIUM

public static final int MILLENNIUM
Millennium.

See Also:
  - Constant Field Values

### CENTURY

public static final int CENTURY
Century.

See Also:
  - Constant Field Values

### DECADE

public static final int DECADE
Decade.

See Also:
  - Constant Field Values

### QUARTER

public static final int QUARTER
Quarter.

See Also:
  - Constant Field Values

### MILLISECOND

public static final int MILLISECOND
Millisecond.

See Also:
  - Constant Field Values

### MICROSECOND

public static final int MICROSECOND
Microsecond.

See Also:
  - Constant Field Values

### NANOSECOND

public static final int NANOSECOND
Nanosecond.

See Also:
  - Constant Field Values

### DAY_OF_YEAR

public static final int DAY_OF_YEAR
Day of year.

See Also:
  - Constant Field Values

### ISO_DAY_OF_WEEK

public static final int ISO_DAY_OF_WEEK
ISO day of week.

See Also:
  - Constant Field Values

### ISO_WEEK

public static final int ISO_WEEK
ISO week.

See Also:
  - Constant Field Values

### ISO_WEEK_YEAR

public static final int ISO_WEEK_YEAR
ISO week-based year.

See Also:
  - Constant Field Values

### DAY_OF_WEEK

public static final int DAY_OF_WEEK
Day of week (locale-specific).

See Also:
  - Constant Field Values

### WEEK

public static final int WEEK
Week (locale-specific).

See Also:
  - Constant Field Values

### WEEK_YEAR

public static final int WEEK_YEAR
Week-based year (locale-specific).

See Also:
  - Constant Field Values

### EPOCH

public static final int EPOCH
Epoch.

See Also:
  - Constant Field Values

### DOW

public static final int DOW
Day of week (locale-specific) for PostgreSQL compatibility.

See Also:
  - Constant Field Values

## Constructor Details

### DateTimeFunction

public DateTimeFunction(int function, int field, Expression arg1, Expression arg2)

## Method Details

### getField

public static int getField(String name)
Get date-time field for the specified name.

Parameters:
  `name` - the name
Returns:
  the date-time field
Throws:
  `DbException` - on unknown field name

### getFieldName

public static String getFieldName(int field)
Get the name of the specified date-time field.

Parameters:
  `field` - the date-time field
Returns:
  the name of the specified field

### getValue

public Value getValue(SessionLocal session, Value v1, Value v2)
Description copied from class: `Function1_2`
Returns the value of this function.

Overrides:
  `getValue` in class `Function1_2`
Parameters:
  `session` - the session
  `v1` - the value of first argument
  `v2` - the value of second argument, or `null`
Returns:
  the resulting value

### dateadd

public static Value dateadd(SessionLocal session, int field, long count, Value v)
DATEADD function.

Parameters:
  `session` - the session
  `field` - the date-time field
  `count` - count to add
  `v` - value to add to
Returns:
  result

### optimize

public Expression optimize(SessionLocal session)
Description copied from class: `Expression`
Try to optimize the expression.

Specified by:
  `optimize` in class `Expression`
Parameters:
  `session` - the session
Returns:
  the optimized expression

### getUnenclosedSQL

public StringBuilder getUnenclosedSQL(StringBuilder builder, int sqlFlags)
Description copied from class: `Expression`
Get the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization. Enclosing '(' and ')' are never appended.

Overrides:
  `getUnenclosedSQL` in class `Function1_2`
Parameters:
  `builder` - string builder
  `sqlFlags` - formatting flags
Returns:
  the specified string builder

### getName

public String getName()
Description copied from interface: `NamedExpression`
Get the name.

Returns:
  the name in uppercase