I’m tying to create a variable for the date of tomorrow. I’ve taken multiple attempts with logics but I still haven’t succeeded.
My goal is to have a label for the date of tomorrow so I can use this for push notifications . Can anyone help me out with an example how I can arrange this?
I made a few flows which determine the month (January, February etc.) and day (1st day, 2nd day etc.). I needed them to be in separate logic cards for my flows. I found it easier to determine those seperately, rather than determining the exact date in one card.
It basically boils down to twelve different flows for the months (which checks every day at 0:05 in the night which month it is) and a flow that sets a number variable to 1 when it’s the first of the month, and increments it otherwise, every day at 0:04 in the night. That way it doesn’t matter whether the month has 31 or 30 days (or 29/28 > February). All you need to do, is adjust the flow for the day. I’ll share it in a bit.
Have u managed it allready? Coz the “solution” of Neuron44 is calculating the day of today, and not of tomorrow.
I still can’t do it.
What i want, is to know if a certain date is tomorrow or the day after tomorrow. Or… i have a date, and i want to know what day of the week that is.
Iam, butthat can’t do it, yet… more logic would be javascript logic From the same creator. I allready have requested a lot of features. But apparently there are more people that want the same. Why creating a new topic, or solve it behind others back?
I also requested date calculations at better logic but that creator does not respond. So, lets try it this way. Somehow, someway, sombody will make it possible. It is very weird that almost everything is possible but not calculating time/date. I am a theorist, sadly i cannot program however, i do understand how it works. So, i know it is very easy to make it possible for a programmer.
In this case, OT never got an awnser, and he never came back to it, so i am curriuous.
Found an example in HomeyScript that can help you further, I hope, will need some adjustments for you:
// getDayOfYear.js
// Get the Day of the Year and set it to a BetterLogic Var
// first create a numeric variable in BetterLogic with the name below: DayOfYear
let BLVarName="DayOfYear";
let testDay = new Date();
Date.prototype.getDayOfYear = function() {
let thisYear = new Date(this.getFullYear(),0,1,0,0,0,0); //yyyy,jan=0, 1st day = 1, 0h,0min.,0 Sec.,0 mSec.
let today = new Date(this.getFullYear(), this.getMonth(), this.getDate(),0,0,0,0); //today , 0h,0min.,0 Sec.,0 mSec.
let aday = 24*60*60*1000; // 24h x Min x Sec x mSec.
return 1+(today - thisYear)/aday;
};
let dayOfYear = testDay.getDayOfYear();
console.log(dayOfYear);
console.log(Math.round(dayOfYear));
let BLApp = await Homey.apps.getApp({id:"net.i-dev.betterlogic" });
let result = await BLApp.apiPut("/" + BLVarName + "/" + Math.round(dayOfYear) );
return true;
For the Day of week:
// my script createDayTag.js
const DAYS = ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'];
var Weekdag = DAYS[new Date().getDay()];
await setTagValue("weekdag", {type: "string", title: "Weekdag"}, DAYS[new Date().getDay()]);
console.log("weekdag", Weekdag);
return(true);
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
just test it, but both, mine and that line will make it 31 sept.
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 so that i added now.
i found my own fault, i set setdate with month 9, of course it had to be 8
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);