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);
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
At the time 4.30 i run that homeyscript to determine the next day date.