Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.0 » SQL Anywhere Server - SQL Reference » Using SQL » SQL functions » Alphabetical list of functions

 

WEEKS function [Date and time]

Returns the number of weeks between two dates.

Syntax 1
WEEKS( [ datetime-expression, ] datetime-expression )
Syntax 2
WEEKS( datetime-expression, integer-expression )
Parameters
  • datetime-expression   A date and time.

  • integer-expression   The number of weeks to be added to the datetime-expression. If integer-expression is negative, the appropriate number of weeks is subtracted from the datetime value. If you supply an integer-expression, the datetime-expression must be explicitly cast as a datetime data type.

Remarks

The value returned by the WEEKS function is calculated by dividing by seven the number of days between the two dates, and then rounding down.

Given a single date, the WEEKS function returns the number of weeks since 0000-02-29.

Given two dates, the WEEKS function returns the integer number of weeks between them. It is recommended that you use the DATEDIFF function [Date and time] instead for this purpose.

Given one date and an integer, the WEEKS function adds the integer number of weeks to the specified date. It is recommended that you use the DATEADD function instead for this purpose. See DATEADD function [Date and time].

Syntax 1 returns an integer. Syntax 2 returns a timestamp.

See also

For information about casting data types, see CAST function [Data type conversion].

Standards and compatibility
  • SQL/2003   Vendor extension.

Example

The following statements return the value 8, signifying that the second date is eight weeks after the first. It is recommended that you use the second form (DATEDIFF).

SELECT WEEKS( '1999-07-13 06:07:12',
   '1999-09-13 10:07:12' );

SELECT DATEDIFF( week,
   '1999-07-13 06:07:12',
   '1999-09-13 10:07:12' );

The following statement returns the value 104270.

SELECT WEEKS( '1998-07-13 06:07:12' );

The following statements return the timestamp 1999-06-16 21:05:07.0. It is recommended that you use the second form (DATEADD).

SELECT WEEKS( CAST( '1999-05-12 21:05:07'
AS TIMESTAMP ), 5);
SELECT DATEADD( week, 5, '1999-05-12 21:05:07' );