Day of the week (dow) at DATE $ / TIME $.

Here you'll find the updated available
mezjoc
Posts: 20
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 14 times
Been thanked: 7 times

Day of the week (dow) at DATE $ / TIME $.

Post by mezjoc »

I would have needed to determine the day of the week (e.g. Friday). I ask for your help in solving this problem. Thanks: mezjoc
User avatar
Electroguard
Posts: 181
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 40 times
Been thanked: 102 times

Re: Day of the week (dow) at DATE $ / TIME $.

Post by Electroguard »

UNIX date started from January 1st 1970, and a quick search said it was a monday
Therefore you can use the Annex Unix date functions to work out how many days have elapsed since the beginning of unix time to any date of interest (eg: the current date).
Dividing the elapsed days by 7 will obviously give the number of elapsed weeks.
More importantly, the remainder of dividing by 7 (modulo) will give the number of days which have elapsed since monday.
So something like (elapsed_unix_days MOD 7) can be used to index a simple 7 element array of day names (eg: 1="Monday" to 7="Sunday"),

Unix Time functions
The following functions utilises the time following the “Unix Time Stamp” format :

DATEUNIX(date$), TIMEUNIX(time$), UNIXDATE$(value [,format]), UNIXTIME$(value)

The “Unix Time Stamp” is a way to track time as a running total of seconds.
This count starts at the Unix Epoch on January 1st, 1970 at UTC.
Therefore, the unix time is merely the number of seconds between a particular date and the Unix Epoch.
In synthesys :
- DATEUNIX("01/01/18") returns the number of seconds between the 01/01/1970 and the 01/01/2018 (1514764800)
- UNIXDATE$("1532773308") returns 28/07/18
mezjoc
Posts: 20
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 14 times
Been thanked: 7 times

Re: Day of the week (dow) at DATE $ / TIME $.

Post by mezjoc »

Dear Electroquard!
Thank you for quick answer. The solution is logical. (I could have figured that out on my own :shock: ). I will inform you of the result.
User avatar
Fernando Perez
Posts: 106
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 55 times
Been thanked: 54 times

Re: Day of the week (dow) at DATE $ / TIME $.

Post by Fernando Perez »

Will you be working with dates greater than January 1, 1970?
In that case, you can use this statement, which returns you the name of the day of the week:

Code: [Local Link Removed for Guests]

DIM dayWeek$(6) = "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"
cDate$ = "23/07/30"
 
nDay = (dateUnix(cDate$)/86400) MOD 7
wlog nDay, dayWeek$(nDay)
If not, it can be easily set to deliver the number of the day of the week. Do you work with Sunday = 0 or with Monday = 0?
mezjoc
Posts: 20
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 14 times
Been thanked: 7 times

Re: Day of the week (dow) at DATE $ / TIME $.

Post by mezjoc »

Hello!
This is a possible solution.

Code: [Local Link Removed for Guests]

'/program/lcd_20x4.bas/2021.04.29.
'DS18B20/DAT-->NodeMCU/D4/GPIO2,GND,3V3
'LCD/SDA-->D1mini/D2/GPIO4
'LCD/SCL-->D1mini/D3/GPIO0
'LCD/POWER-->GND,5V
i2c.setup 4,0  'SDA-->GPIO4, SCL-->GPIO0
lcd.init 39,20,4
'DIM dayWeek$(6) = "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"
'!!!in Hungarian
DIM dayweek$(6) = "CSUTORTOK", "PENTEK", "SZOMBAT", "VASARNAP", "HETFO", "KEDD", "SZERDA"
timer0 1000, cycle
wait

cycle:
lcd.print 1,1,date$(2)
lcd.print 1,2,time$
'cDate$="08/04/21"  'DD/MM/YY
'nDay = (dateUnix(cDate$)/86400) MOD 7
nday = (dateUnix(date$(1))/86400) MOD 7
lcd.print 1,3,dayweek$(nday)
temp$=tempr$(2,1)
hom=int(val(temp$)*10)/10
hom$=str$(hom, "%3.1f")
lcd.print 1,4,"Temp=" & hom$ & " Cfok    "
return
User avatar
Fernando Perez
Posts: 106
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 55 times
Been thanked: 54 times

Re: Day of the week (dow) at DATE $ / TIME $.

Post by Fernando Perez »

I don't think it works correctly, since it uses date$(1) on line 19. And according to the help of Annex, the 1 is for the American format.
image.png
For Hungary I think it is better to use only date$, without formatting.
You do not have the required permissions to view the files attached to this post.
User avatar
Fernando Perez
Posts: 106
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 55 times
Been thanked: 54 times

Re: Day of the week (dow) at DATE $ / TIME $.

Post by Fernando Perez »

I beg your pardon. I did not know that in Hungary the format is yyyy-mm-dd :roll:
mezjoc
Posts: 20
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 14 times
Been thanked: 7 times

Re: Day of the week (dow) at DATE $ / TIME $.

Post by mezjoc »

No problem. We do everything backwards.
Date = YY / MM / DD.
Time = HH: MM: SS.
Name = 1. surname 2. first name
I'm working with Google Translate! ;)
mezjoc
Posts: 20
Joined: Tue Mar 09, 2021 4:26 pm
Location: Fót / Hungary
Has thanked: 14 times
Been thanked: 7 times

Re: Day of the week (dow) at DATE $ / TIME $.

Post by mezjoc »

Would you help?
Attachment to Canadian format?
DATE $ (2)
Thanks.
nedudgi
Posts: 9
Joined: Tue Feb 09, 2021 7:01 pm
Location: Budapest, Hungary
Has thanked: 26 times
Been thanked: 2 times

Re: Day of the week (dow) at DATE $ / TIME $.

Post by nedudgi »

[quote=mezjoc post_id=653 time=1619800630 user_id=101]
No problem. We do everything backwards.
Date = YY / MM / DD.
Time = HH: MM: SS.
Name = 1. surname 2. first name
I'm working with Google Translate! ;)
[/quote]
I am not sure, that we are backwards. ISO declared the date format sequence YYYYMMDD, a long-long time ago. This format makes sorting by date more easier for computers. [url][External Link Removed for Guests][/url]
Post Reply