Tutorial Gateway

  • C
  • C#
  • Python
  • SQL
  • Java
  • JS
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs
  • MySQL

MySQL WEEKOFYEAR

MySQL WEEKOFYEAR function is one of the MySQL Date Functions, which returns the Calendar week number from the given date. This MySQL WEEKOFYEAR function returns value range from 1 to 53.

Let us see how to use this WEEKOFYEAR function to get the Week of Year in MySQL from an expression with an example. The basic syntax of the WEEKOFYEAR() Function in MySQL is as shown below:

WEEKOFYEAR(date or expression);

MySQL WEEKOFYEAR function Example

The following queries help you understand the basic use of the Week of Year function. Here, we are returning the Calendar Week number from the date expression, and the Date and time expression.

TIP: This WEEKOFYEAR Date Function is equivalent to WEEK(date, 3).

SELECT WEEKOFYEAR('2018-12-25');

SELECT WEEKOFYEAR('2018-07-25 09:14:27');

SELECT WEEKOFYEAR('2018-10-25 09:14:27');
MySQL WEEKOFYEAR Function 2

Let us see another example of MySQL WEEK OF YEAR function. Here, we are returning the Week number from the current date and time returned by the Now() function, and the current date returned by CURDATE() function.

SELECT WEEKOFYEAR(NOW());

SELECT WEEKOFYEAR(CURDATE());
MySQL WEEKOFYEAR Function 3

MySQL WEEKOFYEAR Function Example 2

The following query show what happens when we try to find the calendar week number from a date in string format or invalid dates.

SELECT WEEKOFYEAR(CURDATE() + 120);

SELECT WEEKOFYEAR(0);

SELECT WEEKOFYEAR('2012-22-22');
MySQL WEEKOFYEAR Function 4

From the above screenshot, WEEKOFYEAR(0) means we are trying to extract a week number from a zero date part. That’s why it returns NULL. Within the Last statement, WEEKOFYEAR(‘2012-22-22’); is returning NULL. Because it is an invalid MySQL date.

Filed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions

Copyright © 2021ยท All Rights Reserved by Suresh.
About | Contact | Privacy Policy