Page 1 of 1

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

Posted: Sun Oct 27, 2024 10:43 pm
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

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

Posted: Mon Oct 28, 2024 8:32 am
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

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

Posted: Mon Oct 28, 2024 2:31 pm
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

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

Posted: Fri Nov 01, 2024 6:57 pm
by woody
Perfecto !

Sincere thanks.