This topic describes how to use the date function WEEK in Realtime Compute.

Syntax

BIGINT WEEK(DATE date)
BIGINT WEEK(TIMESTAMP timestamp)

Input parameters

Parameter Data type
date DATE
timestamp TIMESTAMP

Description

Returns the week number of the specified date in a year. The week number ranges from 1 to 53.

Example

  • Test data
    dateStr (VARCHAR) date1 (DATE) ts1 (TIMESTAMP)
    2017-09-15 2017-11-10 2017-10-15 00:00:00
  • Test statements
    SELECT WEEK(TIMESTAMP '2017-09-15 00:00:00') as int1,
     WEEK(date1) as int2,
     WEEK(ts1) as int3,
     WEEK(CAST(dateStr AS DATE)) as int4
    FROM T1;
  • Test results
    int1 (BIGINT) int2 (BIGINT) int3 (BIGINT) int4 (BIGINT)
    37 45 41 37