Calculate date of tomorrow

Two awesome replies… however, i dont understand (yet) what it all means but i will figure that out.
I can read js so i bet i can rewrite some… i know about homeyscript but coz i am not a coder, i never took time for it… i will give it a 8th chance :slight_smile:

Thnx!

I fixed it!!
The output is today: 19-09-2020
the script is now:

let BLVarName=“DatumVanMorgen”;
let CurrentDate = new Date();

TomorrowDate = ‘d-m-Y’
.replace(‘d’, (“0” + (CurrentDate.getDate() + 1)).toString().slice(-2))
.replace(‘m’, (“0” + (CurrentDate.getMonth() + 1)).toString().slice(-2))
.replace(‘Y’, CurrentDate.getFullYear());

console.log(TomorrowDate);
let BLApp = await Homey.apps.getApp({id:“net.i-dev.betterlogic” });
let result = await BLApp.apiPut("/" + BLVarName + “/” + TomorrowDate);
return true;

1 Like

Perhaps test this a bit better, because it will fail on most last-day-of-the-month days :frowning:

For example:

  • the next day from 31-1-2020 will be 32-1-2020
  • the next day from 29-2-2020 will be 30-2-2020
  • the next day from 30-4-2020 will be 31-4-2020

I think this will help. Google is my friend🤗

1 Like

This won’t work coz it’s output is: 2020-09-20T07:02:55.108Z

And I need: 20-09-2020

It is what I thought also. But it will get date by that instance so… but I’ll test it to be sure

You can of course modify your script so it uses that code:

let CurrentDate = new Date();

CurrentDate.setDate(CurrentDate.getDate() + 1);

const TomorrowDate = 'd-m-Y'
.replace('d', ('0' + CurrentDate.getDate()).toString().slice(-2))
.replace('m', ('0' + CurrentDate.getMonth() + 1).toString().slice(-2))
.replace('Y', CurrentDate.getFullYear());

just test it, but both, mine and that line will make it 31 sept. :frowning:

holy moly… if i set date to 30 sept, it will be 31, when i set 31 sept, it will be 1 okt. :S how weird?

i think i allready know why… but as far as i know now, i cannot test en should wait till 30 sept.
however, i think als now that the add of Marcel_Ubels is good suggestion :slight_smile: so that i added now.

Install Node.js (or open the developer console of every recent-ish browser) and you can test all the date-related code easily from the commandline.

Also, my example code contains an issue, you need to add parentheses around the getMonth() code:

let CurrentDate = new Date();

CurrentDate.setDate(CurrentDate.getDate() + 1);

const TomorrowDate = 'd-m-Y'
.replace('d', ('0' + CurrentDate.getDate()).toString().slice(-2))
.replace('m', ('0' + (CurrentDate.getMonth() + 1)).toString().slice(-2))
.replace('Y', CurrentDate.getFullYear());

i found my own fault, i set setdate with month 9, of course it had to be 8 :slight_smile:
with your correction, i have tested it, and now it works!!!

thank you very much!!
my whole script is now:

let BLVarName=“DatumVanMorgen”; //the variable for BetterLogic
let CurrentDate = new Date();
//CurrentDate = new Date(2020,8,30)
CurrentDate.setDate(CurrentDate.getDate() + 1);

const TomorrowDate = ‘d-m-Y’
.replace(‘d’, (‘0’ + CurrentDate.getDate()).toString().slice(-2))
.replace(‘m’, (‘0’ + (CurrentDate.getMonth() + 1)).toString().slice(-2))
.replace(‘Y’, CurrentDate.getFullYear());

console.log(TomorrowDate);
let BLApp = await Homey.apps.getApp({id:“net.i-dev.betterlogic” });
let result = await BLApp.apiPut("/" + BLVarName + “/” + TomorrowDate);
return true;

By The Way… what i have made now, is a fully automated alarmclock.
i add my schedule to apple agenda and with icalCalendar i can now know if i have to work tomorrow or not. before i go to sleep i will get an daily update via google hub. it tells me the temperature, how much power i have collected today, if i have to work or not, etc…
then, the next morning, my alarm will go off 1 hour before i have to start to work. only thing i have to do is adding the schedule.

this was needed coz icalcalender only checks the next event and collect its date. now i can verify if that date is tomorrow or not. as long as that date is not the same, i don’t have to work the next day :slight_smile:
At the time 4.30 i run that homeyscript to determine the next day date.

1 Like

image

Happy to have found your script for the day of the week, but it returns the wrong day for me.
This may be related to time zone? I am 1 hour later than Western Europe. Its after midnight and I just ran it, it still says Monday, but it is Tuesday already.

Was something deprecated? Any other idea?

It only works well after it is midnight in Londen I’m afraight.

1 Like

Thank you. I will do it the old fashioned way. :innocent:

image

1 Like

@Rrrr you can use the BetterLogic Library flowcard: format date.
Fill it with ddd or dddd and you will get the day, based on your timezone (can be configured or overruled).

1 Like

That is by far the most elegant way, thank you.

I read the BLL support pages in the app settings.
Can you calculate date of tomorrow?

1 Like

Well, yeah, but since date in this flowcard is just an argument (not coding), you will need the “Execute BLL Expression (as Tag)” card (or you would first need to set the date in another card).
Then place this in the expression:

date('dddd', new Date(new Date().setDate(new Date().getDate()+1)))

That’s it.



What you also could do, is create a function in the BLL App Settings called f.i. addDays, with this in it’s body:

function (days) {
  let d = new Date();
  return new Date(d.setDate(d.getDate()+days));
}

then write this in the Expressioncard:

date('dddd', addDays(1))

Thus, what you have now is:

and

Or, if you want know the day after tomorrow:

1 Like

@Arie_J_Godschalk :heartbeat:
Thank you for your complete answer and the options. Amazing to see how powerful BLL can be.

1 Like

And the developer

1 Like

Thanks!

And please note, all those codings can be used in any flowcard that supports bll coding, if you place it within {[ ]}
So, this coding can f.i. be used directly within a Google Service Speak flowcard, without the need for a ExpressionAsTag card.