15.00 - TRUNC(Date) - Teradata Database

Teradata Database SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Content Type
Programming Reference
Publication ID
B035-1145-015K
Language
English (United States)
Last Update
2018-09-24

TRUNC(Date)

Purpose  

Returns date_value with the time portion of the day truncated to the unit specified by fmt.

Syntax  

where:

 

Syntax element …

Specifies …

TD_SYSFNLIB

the name of the database where the function is located.

date_value

a numeric or timestamp argument.

fmt

a character argument.

If fmt is NULL, NULL is returned.

If fmt is omitted, date_value is truncated to the nearest day. Sunday is considered the first day of the week. For ISO years, Monday is considered the first day of the week.

If fmt is not valid, an error is returned.

ANSI Compliance

This is a Teradata extension to the ANSI SQL:2011 standard.

Invocation

TRUNC(DATE) is an embedded services system function. For information on activating and invoking embedded services functions, see “Embedded Services System Functions” on page 24.

Argument Types and Rules

Expressions passed to this function must have one of the following data types:

  • date_value = DATE, TIMESTAMP, or TIMESTAMP WITH TIME ZONE
  • fmt = VARCHAR CHARACTER SET LATIN
  • For the fmt argument, you can also pass values with data types that can be converted to VARCHAR using the implicit data type conversion rules that apply to UDFs. Implicit type conversion is not supported for the date_value argument.

    Note: The UDF implicit type conversion rules are more restrictive than the implicit type conversion rules normally used by Teradata Database. If an argument cannot be converted to the required data type following the UDF implicit conversion rules, it must be explicitly cast.

    For details, see “Compatible Types” in SQL External Routine Programming.

    Date Formats for TRUNC

     

    Element

    Description

    CC
    SCC

    One year greater than the first two digits of a 4-digit year.

    SYYY
    YYYY
    YEAR
    SYEAR
    YYY
    YY
    Y

    Year (rounds up on July 1)

    IYYY
    IYY
    IY
    I

    ISO year

    MONTH
    MON
    MM
    RM

    Month (rounds up on the 16th day)

    Q

    Quarter (rounds up on the 16th day of the 2nd month of the quarter)

    WW

    Same day of the week as the 1st day of the year

    IW

    Same day of the week as the first day of the ISO year

    W

    Same day of the week as the first day of the month

    DDD
    DD
    J

    Day

    DAY
    DY
    D

    Starting day of the week

    HH
    HH12
    HH24

    Hour

    MI

    Minute

    Result Type

    TRUNC is a scalar function whose return data type is DATE.

    Example  

    The following query:

    SELECT TRUNC(CAST('2003/09/17' AS DATE), 'D') (FORMAT 'yyyy-mm-dd'); 

    returns the result 2003-09-14. The date was truncated to the first day of that week.

    Example  

    The following query:

    SELECT TRUNC(CAST('2003/09/17' AS DATE), 'RM') (FORMAT 'yyyy-mm-dd'); 

    returns the result 2003-09-01. The date was truncated to the beginning of the month.