Type: Function
Syntax: WEEK([datetime])
Description: This function has two different modes of operation, based on whether an argument is provided or not. With no arguments, it returns the duration of a week in seconds (604800
). With a datetime argument, it returns the week of the year (between 1 and 52) for the provided datetime
Sample usage:
WEEK()
is equal to604800
WEEK(created_at)
returns the week of the year for thecreated_at
field valueWEEK(DATE(2023, 08, 27))
returns34
.AVG(closed_at-created_at)/WEEK()
returns the time elapsed in weeks between the creation and closing of a record. Note that the difference between two dates (closed_at-created_at
) is always returned in seconds.created_at + 2*WEEK()
returns thecreated_at
field value plus 2 weeks (14 days).