Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numeric representation of the day of the week MySql Vs PHP

In my PHP code I'm using date("N") ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday).

Now when I wanted to make a query to search for a specific date.

I found that in MySQL:

  • The date_format using %w will return (0=Sunday..6=Saturday)

  • The DAYOFWEEK(date) will return (1 = Sunday .. 7=Saturday)

Is there a fast way to fix this issue without doing some PHP ?

like image 453
Tarek Avatar asked Dec 30 '25 23:12

Tarek


1 Answers

As is said in the comments:

Subtract or add one (either to PHP or to your MySQL query).

like image 94
Naftali Avatar answered Jan 01 '26 12:01

Naftali