Page 1 of 1

Trying to get the day of the week (numeric)

Posted: 10 Feb 2018 20:53
by clive.pottinger
Hello,

The help page for date formatting indicates that it is possible to get the "stand-alone day of week (Text/Number)" by using the 'c' symbol. However, no matter what I try, all I can get is the short textual day of the week:

Code: Select all

dow = "{getDate(1999,12,31), dateformat, c}";
gives me "Fri".

What do I need to do to get a returned value of 5 instead of "Fri"?

Many thanks.

Re: Trying to get the day of the week (numeric)

Posted: 11 Feb 2018 03:52
by pmgnt
dow = "{getDate(1999,12,31), dateformat, EEEE}"

Re: Trying to get the day of the week (numeric)

Posted: 11 Feb 2018 05:10
by clive.pottinger
pmgnt wrote:dow = "{getDate(1999,12,31), dateformat, EEEE}"
Unfortunately, this returns "Friday", not 5.

Re: Trying to get the day of the week (numeric)

Posted: 11 Feb 2018 07:57
by Desmanto
I never realize there is pattern character 'c' there. I test the pattern and also get "Fri". Seems we missed something out to get the result as number. Trying multiple 'cccc' also give "Friday".

I used to face the same problem, but I simply solved it using division and modulus.

Code: Select all

dow = (getDate(2018,2,10)/ 86400000 + 5) % 7;
divided by 86400000 miliseconds will give result in days after 1 January 1970. Plus 5 because the starting day at 1 January 1970 is Thursday (index 4 from 0 based on Sunday), but my GMT+0700 deduct 7 hours to be less than 1 January 1970. So Friday, 2 January 1970 will be evaluted to 0 at the modulus 7; it should 5 (from 0 based). That's why I plus 5. Depends on your timezone, you maybe need to +4 instead.

Re: Trying to get the day of the week (numeric)

Posted: 11 Feb 2018 14:38
by pmgnt
clive.pottinger wrote:
pmgnt wrote:dow = "{getDate(1999,12,31), dateformat, EEEE}"
Unfortunately, this returns "Friday", not 5.
Sorry my bad. Didnt read the question correctly.

Re: Trying to get the day of the week (numeric)

Posted: 11 Feb 2018 14:55
by clive.pottinger
Desmanto wrote:I never realize there is pattern character 'c' there. ... I used to face the same problem, but I simply solved it using division and modulus.

Code: Select all

dow = (getDate(2018,2,10)/ 86400000 + 5) % 7;
Thanks Desmanto. I knew I could do it arithmatically; I just thought I was using 'c' incorrectly. Good to know it doesn't actually work as indicated.
pmgnt wrote:Sorry my bad. Didnt read the question correctly.
No problem.

Re: Trying to get the day of the week (numeric)

Posted: 13 Feb 2018 07:31
by Martin
Hi,

'c' is a strange one that returned the text presentation on most or even all devices. Seems that Google also removed it from the documentation for some reason.
Google added a new pattern 'u' on Android 7+ to get the numeric day of week. I recommend to use this one if you're on a current version of Android.
I'll update the documentation and mark 'c' as deprecated.

Regards,
Martin

Re: Trying to get the day of the week (numeric)

Posted: 23 Apr 2019 21:57
by clive.pottinger
Thanks again. Using 'u' worked.