cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

what is the difference between weekday and dayofweek function in spark SQL?

mrvi2310
New Contributor II

dayofweek: https://docs.databricks.com/sql/language-manual/functions/dayofweek.html

weekday : https://docs.databricks.com/sql/language-manual/functions/weekday.html

According to the documentation , they both are synonym functions.

But when I use it I noticed that weekday starts the day count from Tuesday = 1 weekday vs dayofweek

Would this be considered a bug or do both functions mean different things?

7 REPLIES 7

Anonymous
Not applicable

Hello, @mrvi2310โ€‹! Welcome and thanks for your question. My name is Piper and I'm one of the community moderators. Let's give it a bit to see how the other members respond. We'll circle back around if we need to.

Hubert-Dudek
Esteemed Contributor III

That's correct for weekday moday=0 for dayofweek Sunday=1.โ€‹

โ€‹

You can also look for documentation here https://spark.apache.org/docs/latest/api/python/reference/api/pyspark.sql.functions.dayofweek.html

โ€‹https://spark.apache.org/docs/latest/api/sql/index.html

Kaniz
Community Manager
Community Manager

Hi @mrvi2310โ€‹ , As @Hubert Dudekโ€‹ has rightly mentioned, here are the screenshots:-

Screenshot 2021-12-13 at 5.11.21 PMScreenshot 2021-12-13 at 5.10.44 PMReferences:- https://spark.apache.org/docs/latest/api/sql/

-werners-
Esteemed Contributor III

Maybe update the databricks docs, as there is indeed stated that they are synonyms.

Kaniz
Community Manager
Community Manager

Hi @Werner Stinckensโ€‹ , It's truly appreciated that you flagged the information here. However, as I've checked the databricks docs now, it's mentioned the same as I and @Hubert Dudekโ€‹have stated.

It states that these functions are synonyms of the function extract(DAYOFWEEK FROM expr) and are not synonyms to each other. I've attached the screenshots below.

References:- https://docs.databricks.com/sql/language-manual/functions/dayofweek.html

https://docs.databricks.com/sql/language-manual/functions/weekday.html

Screenshot 2021-12-13 at 6.07.09 PMScreenshot 2021-12-13 at 6.06.40 PM 

UPDATE:-

An update is required in the function WEEKDAY where it's stated that it returns an INTEGER where 1 = Sunday and 7 = Saturday.

It should have been that it returns an integer where 0 = Monday, 6 = Sunday).

-werners-
Esteemed Contributor III

ah yes, my bad!

Kaniz
Community Manager
Community Manager

No worries!

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.