Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
stevelord
Specialist
Specialist

Function to pull the day name from a date value?

Hi All, I need to pull the day name out of a date - so values like Sun Mon Tue Wed Thu Fri Sat coming out of values like 12/21/2015. What's the function?  (I'll be doing trial and error while this post waits for a correct answer.   Someone wants to know most popular day of the week for users to log their entries.)

12 Replies
sunny_talwar

Try WeekDay() function

swuehl
MVP
MVP

(I'll be doing trial and error while this post waits for a correct answer.  

You shouldn't do this by trial and error. There is a reference manual and a HELP function available, besides lots of books, online videos, blogs etc.

The chapter in the HELP is called: 'Date and time functions'

stevelord
Specialist
Specialist
Author

Thanks, maybe I meant to say 'consulting the reference manual in case there's no quick answer'.   Reference manual might've had a straight answer this time, but plenty of times it has answered the questions to the left and right of mine and I'm doing 'trial and error' from the reference manual itself.  So I developed a habit to get the ball rolling on qlikcommunity in case my own effort comes up empty.  And I share my answer if I get it before anyone else does (citing wherever I got it from).

JonnyPoole
Former Employee
Former Employee

Try WWW or WWWW as the date mask.  The inner date# may not be required for you if you are already reading as a date value.

Date( Date#( '12/21/2015','MM/DD/YYYY'), 'WWWW')  

JonnyPoole
Former Employee
Former Employee

even better !

=if(  Date( Date#( '12/21/2015','MM/DD/YYYY'), 'WWW')  = 'Mon', 'Hooray its a monday', 'try again')

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Jonathan,

date(mydate,'WWWW') does not extract the weekday from a date. It only formats the display. If the intention is to bucket by weekday, 'WWWW' Monday on two different dates would return two buckets, not a single "Monday" bucket.

-Rob

Not applicable

Hi Steve try this:

=weekday(date#('12/21/2015', 'MM/DD/YYYY')) in a Text Box! The result will be: Mon (Monday)

I hope that it help you !

First you put a format for the string and then applies the weekday() function.

Regards, Agustin

JonnyPoole
Former Employee
Former Employee

True - it won't be effective for list boxes or chart dims , just conditional checks etc..

For a chart dim or list box , here is a hack:

=Date(MakeDate(2015,12,20)+ WeekDay( Date),'WWW')

-  weekday() returns 0 for Sunday and 6 for Saturday

-  2015/12/20  , or yesterday, was a sunday. That will never change (i hope!)

-  so 2015/12/20  + (0)  ->  Sunday 2015/12/20 displayed as 'Sun'  ... it will resolve to 'sun' for every data record with a  day of the week  that is a sunday

- so 2015/12/20  + (1)  ->  Monday 2015/12/21 displayed as 'Mon'  ... it will resolve to 'mon' for every data record with a  day of the week  that is a monday

etc..


Capture.PNG

swuehl
MVP
MVP

Ok ...  but what's the advantage over just using

Weekday(Date)

then?