WEEK( ) Function

Returns a number representing the week of the year from a Date or DateTime expression.

WEEK(dExpression | tExpression [, nFirstWeek] [, nFirstDayOfWeek])

Parameters

  • dExpression| tExpression
    Specifies the Date or DateTime expression for which WEEK( ) returns the week of the year.

    When you omit nFirstWeek and nFirstDayOfWeek, WEEK( ) uses Sunday as the first day of the week.

  • [, nFirstWeek]
    Specifies the requirements for the first week of the year. The following table lists the values for nFirstWeek.

    nFirstWeek

    Description

    0

    Specifies that WEEK( ) return the week that is currently selected in the First Week of Year box on the Regional tab of the Options dialog box.

    1

    First week contains January 1st. This is the default when you omit nFirstWeek.

    2

    The larger half (four days) of the first week is in the current year.

    3

    First week has seven days.

  • [, nFirstDayOfWeek]
    Specifies the first day of the week. The following table lists the values for nFirstDayOfWeek.

    nFirstDayOfWeek

    Description

    0

    Specifies that WEEK( ) return the day that is currently selected in the Week Starts on box on the Regional tab of the Options dialog box.

    1

    Sunday. This is the default when you omit nFirstDayOfWeek and is the first day of the week used in earlier FoxPro versions.

    2

    Monday

    3

    Tuesday

    4

    Wednesday

    5

    Thursday

    6

    Friday

    7

    Saturday

Return Value

Numeric type. WEEK( ) returns a number representing the week of the year.

Remarks

WEEK( ) returns a number from 1 to 53 that represents the week of the year. For example, WEEK( ) returns 1 for the first week of the year, 2 for the second week of the year, and so on. Note that a week can be split between years — the first week of the year can be in the current year and the previous year.

Example

The following example displays the week of the year for today's date and for a specific date.

CLEAR
? WEEK(DATE( ))
? WEEK({^1998-02-16})  && Displays 8

See Also

Reference

CDOW( ) Function

DAY( ) Function

DOW( ) Function

SET FDOW Command

SET FWEEK Command

SYS( ) Functions Overview

Other Resources

Functions