Page 1 of 2

What day was yesterday?

Posted: Fri Jul 30, 2021 10:31 am
by Fernando Perez
How can I find out what day it was yesterday?
I thought of using this:

Code: [Local Link Removed for Guests]

day$ = unixDate$((dateUnix(date$) - 86400))
wlog day$
But it always returns the date two days ago, not just one.
Why is this happening?
Can you think of anything to correct it?

Re: What day was yesterday?

Posted: Fri Jul 30, 2021 10:47 am
by cicciocb
Hi Fernand,
It seems right and I have the good result on both ESP8266 and ESP32.

Have you the right Time Zone set in the config page?

Re: What day was yesterday?

Posted: Fri Jul 30, 2021 11:03 am
by Fernando Perez
Good morning Cicciocb.
I am in Spain and I have configured:

CET-1CEST,M3.5.0,M10.5.0/3

Can it be a conflict of my time zone with Annex?
I previously had this problem:

https://groups.google.com/g/annex_wifi_ ... EPW6FWBAAJ

Re: What day was yesterday?

Posted: Fri Jul 30, 2021 11:14 am
by cicciocb
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Fri Jul 30, 2021 11:03 am Good morning Cicciocb.
I am in Spain and I have configured:

CET-1CEST,M3.5.0,M10.5.0/3

Can it be a conflict of my time zone with Annex?
I previously had this problem:

https://groups.google.com/g/annex_wifi_ ... EPW6FWBAAJ
The time zone seems OK.
I have the right information right now on both ESP8266 and ESP32.

Re: What day was yesterday?

Posted: Fri Jul 30, 2021 11:40 am
by Fernando Perez
Yes, it seems strange. Can someone else confirm what is happening in your area / device?
Thanks.
image.png

Re: What day was yesterday?

Posted: Fri Jul 30, 2021 11:53 am
by cicciocb
These are my results :
image.png
image.png
What Annex version are you using ?

Re: What day was yesterday?

Posted: Fri Jul 30, 2021 12:20 pm
by Fernando Perez
version 1.43.2 in ESP8266 Wemos D1 mini
Any other easy way to find out a date by subtracting or adding a number of days to the current date?
Without using unixdate and dateunix?

Re: What day was yesterday?

Posted: Fri Jul 30, 2021 2:15 pm
by Fernando Perez
Marcello, I am afraid to be heavy, but it is important for an ongoing project.
Until now I thought that the optional parameter of the date$ function was solely for the purposes of the date display format (D/M/Y, M/D/Y and Y/M/D), but I see this:

Code: [Local Link Removed for Guests]

wlog "European", date$(0), str$(dateunix(date$(0)), "%10.0f")
wlog "American", date$(1), str$(dateunix(date$(1)), "%10.0f")
wlog "Canadian", date$(2), str$(dateunix(date$(2)), "%10.0f")
image.png
"dateUnix returns the number of seconds from 01/01/1970 to the specified date"

Shouldn't this number of seconds be the same regardless of the country?

Re: What day was yesterday?

Posted: Fri Jul 30, 2021 2:26 pm
by ebs
Hi Fernando,

So it appears that the "dateunix()" function works only for the European (D/M/Y) date format, right?
That's a very good thing to know before doing any date math - thanks.

Regards,
Eric

Re: What day was yesterday?

Posted: Fri Jul 30, 2021 3:50 pm
by ulli
Hi Eric, hi Fernando,

RTFM (Read The Fine Manual): DATEUNIX(date$) converts a date in format dd/mm/yy into UNIX FORMAT.

So your conversion examples are

European 30/07/21 30. day of July 2021 (today)
American 07/30/21 7. day of Trigintember (????) 2021 (some Klingon calendar)
Canadian 21/07/30 21. day of July 2030 (in a couple of years)

That's why the numbers are so different.

Cheers

Ulli