How to determine the WEEKDAY for any given date YYYY-MM-DD

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
Post Reply
User avatar
woody
Posts: 146
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA
Contact:

How to determine the WEEKDAY for any given date YYYY-MM-DD

Post by woody »

Greetings!

Is there a simple utility or function to determine the WEEKDAY (Monday, Tuesday, Wednesday...) from a date YYYYMMDD or 'YYYY-MM-DD' ?

GETWEEKDAY '2024-10-27'
Sunday

?

Sincere thanks!

Woody
Woodley Butler
Automatonics, Inc.
"Find your head in the APL Cloud"
http://www.APLcloud.com
User avatar
Fiona|Dyalog
Posts: 77
Joined: Mon Apr 22, 2013 12:59 pm

Re: How to determine the WEEKDAY for any given date YYYY-MM-

Post by Fiona|Dyalog »

The following expression will work:
'Dddd' (1200⌶) 1 ⎕DT ⊂ 2024 10 27
Therefore your function will work if you create the GETWEEKDAY function as follows:
GETWEEKDAY←'Dddd' (1200⌶) 1 ⎕DT ⊂
      GETWEEKDAY 2024 10 27
Sunday
For more information on 1200⌶, see https://help.dyalog.com/19.0/#Language/ ... tetime.htm

For more information on ⎕DT, see https://help.dyalog.com/19.0/#Language/ ... ons/dt.htm
Vince|Dyalog
Posts: 439
Joined: Wed Oct 01, 2008 9:39 am

Re: How to determine the WEEKDAY for any given date YYYY-MM-

Post by Vince|Dyalog »

Hi Woody,

1) This is a chance to remind you and everybody reading this about Adám's great website, aplcart.info

You can search for something that you want to achieve and it gives you a great APL line to do it.

If you go to aplcart.info and ask it about day of week, it gives you this expression:

(7|1⎕DT⊆) J, where J is an integer array. The result 0 means Sunday, 1 Monday and so on:

e.g.
(7|1⎕DT⊆) 2024 10 27
0
      (7|1⎕DT⊆) 2024 10 28
1
      (7|1⎕DT⊆) 2024 10 29
2
Here is a URL to go to aplcart.info and search for day of week:
https://aplcart.info?q=day%20of%20week

Then, you could also search for day names, combine the expressions and get to a function like Fiona's.

2) By the way, if you are using Dyalog 17.1 and do not have ⎕DT, you could do this:
4⊃2 ⎕NQ'.' 'idntodate'(2 ⎕NQ'.' 'datetoidn' 2024 10 27)
6

      4⊃2 ⎕NQ'.' 'idntodate'(2 ⎕NQ'.' 'datetoidn' 2024 11 1)
4
      4⊃2 ⎕NQ'.' 'idntodate'(2 ⎕NQ'.' 'datetoidn' 2024 10 28)
0
Please note that the idntodate method has 0 for Monday and 6 for Sunday.

Regards,

Vince
User avatar
woody
Posts: 146
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA
Contact:

Re: How to determine the WEEKDAY for any given date YYYY-MM-

Post by woody »

Perfecto !

Sincere thanks.
Woodley Butler
Automatonics, Inc.
"Find your head in the APL Cloud"
http://www.APLcloud.com
Post Reply