Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 



WEEK Function

Description

The WEEK function returns the week in the range of 0 to 53 from specified argument. You can specify the DATE, TIMESTAMP, or DATETIME type; the value is returned in INTEGER type.

You can omit the second argument, mode and must input a value in the range of 0 to 7. You can set that a week starts from Sunday or Monday and the range of the return value is from 0 to 53 or 1 to 53 with this value. If you omit the mode, the system parameter, default_week_format value will be used. The mode value means as follows:

mode

Start Day of the Week

Range

The First Week of the Year

0

Sunday

0~53

The first week that Sunday is included in the year

1

Monday

0~53

The first week that more than three days are included in the year

2

Sunday

1~53

The first week in the year that includes a Sunday

3

Monday

1~53

The first week in the year that includes more than three days

4

Sunday

0~53

The first week in the year that includes more than three days

5

Monday

0~53

The first week in the year that includes Monday

6

Sunday

1~53

The first week in the year that includes more than three days

7

Monday

1~53

The first week in the year that includes Monday

If the mode value is one of 0, 1, 4 or 5, and the date corresponds to the last week of the previous year, the WEEK function will return 0. The purpose is to see what nth of the year the week is so it returns 0 for the 52th week of the year 1999.

SELECT YEAR('2000-01-01'), WEEK('2000-01-01',0);

   year('2000-01-01')   week('2000-01-01', 0)

=============================================

                2000                       0

To see what n-th the week is based on the year including the start day of the week, use 0, 2, 5 or 7 as the mode value.

SELECT WEEK('2000-01-01',2);

    week('2000-01-01', 2)

========================

                      52

Syntax

WEEK(date[, mode])

  • date : Date
  • mode : Value in the range of 0 to 7
Example

SELECT WEEK('2010-04-05');

   week('2010-04-05', 0)

========================

                      14

 

SELECT WEEK('2010-04-05 12:34:56',2);

   week('2010-04-05 12:34:56',2)

===============================

                              14

 

SELECT WEEK('2010-04-05 12:34:56.7890',4);

   week('2010-04-05 12:34:56.7890',4)

====================================

                                  14               

 

SELECT WEEK ('12:34:56');

 

ERROR: Conversion error in date format.

 

SELECT WEEK('2010-04-05',8);

 

ERROR: Conversion error in date format.