org.h2.expression.function

## Class DateTimeFunctions

- java.lang.Object
- - org.h2.expression.function.DateTimeFunctions

    public final class DateTimeFunctions
    extends java.lang.Object

Date and time functions.

### Method Summary

Methods
`static Value` `dateadd(java.lang.String part, long count, Value v)` DATEADD function.
`static long` `datediff(java.lang.String part, Value v1, Value v2)` Calculate the number of crossed unit boundaries between two timestamps.
`static Value` `extract(java.lang.String part, Value value, Mode mode)` Extracts specified field from the specified date-time value.
`static java.lang.String` `formatDateTime(java.util.Date date, java.lang.String format, java.lang.String locale, java.lang.String timeZone)` Formats a date using a format string.
`static int` `getDatePart(java.lang.String part)` Get date part function number from part name.
`static int` `getIntDatePart(Value date, int field, Mode mode)` Get the specified field of a date, however with years normalized to positive or negative, and month starting with 1.
`static java.lang.String[]` `getMonthsAndWeeks(int field)` Return names of month or weeks.
`static boolean` `isDatePart(java.lang.String part)` Check if a given string is a valid date part string.
`static java.util.Date` `parseDateTime(java.lang.String date, java.lang.String format, java.lang.String locale, java.lang.String timeZone)` Parses a date using a format string.
`static Value` `truncateDate(java.lang.String datePartStr, Value valueDate)` Truncate the given date to the unit specified

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

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

### Method Detail

#### dateadd

    public static Value dateadd(java.lang.String part,
                long count,
                Value v)

DATEADD function.

Parameters:
  `part` - name of date-time part
  `count` - count to add
  `v` - value to add to
Returns:
  result

#### datediff

    public static long datediff(java.lang.String part,
                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:
  `part` - the part
  `v1` - the first date-time value
  `v2` - the second date-time value
Returns:
  the number of crossed boundaries

#### extract

    public static Value extract(java.lang.String part,
                Value value,
                Mode mode)

Extracts specified field from the specified date-time value.

Parameters:
  `part` - the date part
  `value` - the date-time value
  `mode` - the database mode
Returns:
  extracted field

#### truncateDate

    public static Value truncateDate(java.lang.String datePartStr,
                     Value valueDate)

Truncate the given date to the unit specified

Parameters:
  `datePartStr` - the time unit (e.g. 'DAY', 'HOUR', etc.)
  `valueDate` - the date
Returns:
  date truncated to 'day'

#### formatDateTime

    public static java.lang.String formatDateTime(java.util.Date date,
                                  java.lang.String format,
                                  java.lang.String locale,
                                  java.lang.String timeZone)

Formats a date using a format string.

Parameters:
  `date` - the date to format
  `format` - the format string
  `locale` - the locale
  `timeZone` - the timezone
Returns:
  the formatted date

#### getDatePart

    public static int getDatePart(java.lang.String part)

Get date part function number from part name.

Parameters:
  `part` - name of the part
Returns:
  function number

#### getIntDatePart

    public static int getIntDatePart(Value date,
                     int field,
                     Mode mode)

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

Parameters:
  `date` - the date value
  `field` - the field type, see `Function` for constants
  `mode` - the database mode
Returns:
  the value

#### getMonthsAndWeeks

    public static java.lang.String[] getMonthsAndWeeks(int field)

Return names of month or weeks.

Parameters:
  `field` - 0 for months, 1 for weekdays
Returns:
  names of month or weeks

#### isDatePart

    public static boolean isDatePart(java.lang.String part)

Check if a given string is a valid date part string.

Parameters:
  `part` - the string
Returns:
  true if it is

#### parseDateTime

    public static java.util.Date parseDateTime(java.lang.String date,
                               java.lang.String format,
                               java.lang.String locale,
                               java.lang.String timeZone)

Parses a date using a format string.

Parameters:
  `date` - the date to parse
  `format` - the parsing format
  `locale` - the locale
  `timeZone` - the timeZone
Returns:
  the parsed date