# \[APP\]\[Pro\] HomeyScript

**URL:** <https://community.homey.app/t/app-pro-homeyscript/854>\
**Category:** Apps\
**Tags:** app, homey-pro\
**Created:** [August 30, 2018, 7:34am UTC](https://community.homey.app/t/app-pro-homeyscript/854 "2018-08-30T07:34:20Z")\
**Posts on this page:** 1\
**Showing post:** 72

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [January 17, 2023, 7:08pm UTC](https://community.homey.app/t/app-pro-homeyscript/854/72 "2023-01-17T19:08:03Z")

</div>

Here is some code. All data will be given as a tag. De tags you don’t need, just add // in front of ‘await tag’. This will give e.g //await tag(‘CurrentDay’, currentDay); and this tag will not be available

```auto
var date = new Date();
date.setDate(date.getDate());
const currentDay = date.getDate();
await tag('CurrentDay', currentDay);
console.log('1 CurrentDay is: ' +currentDay);
const currentMonth = date.getMonth() +1; // getMonth() returns month from 1 to 12
await tag('CurrentMonth', currentMonth);
console.log('2 CurrentMonth is: '+currentMonth);
const currentYear = date.getFullYear();
await tag('CurrentYear', currentYear);
console.log('3 CurrentYear is: '+currentYear);

var date = new Date(); // current date
date.setDate(1); // going to 1st of the month
date.setHours(-1);// going to the last day of the previous Month
const yearPreviousMonth = date.getFullYear();
await tag('YearPreviousMonth', yearPreviousMonth);
console.log('4 YearPreviousMonth is: '+yearPreviousMonth);
const lastDayPreviousMonth = date.getDate();
await tag('LastDayPreviousMonth', lastDayPreviousMonth);
console.log('5 LastDayPreviousMonth is: '+lastDayPreviousMonth);
const previousMonth = date.getMonth() +1;
await tag('PreviousMonth', previousMonth);
console.log('6 PreviousMonth is: '+previousMonth);

var date = new Date(); // current date
date.setDate(1); // going to 1st of the month
date.setMonth(-2)// going back two months
date.setHours(-1);// going to the last day of the previous Month
const yearPreviousTwoMonth = date.getFullYear();
await tag('YearPreviousTwoMonth', yearPreviousTwoMonth);
console.log('7 YearPreviousTwoMonth is: '+yearPreviousTwoMonth);
const previousTwoMonth = date.getMonth() +1;
await tag('PreviousTwoMonth', previousTwoMonth);
console.log('8 PreviousTwoMonth is: '+previousTwoMonth);

var date = new Date();
date.setDate(date.getDate());
function getDaysInMonth(year, month) {
  return new Date(year, month, 0).getDate();
}
const daysInCurrentMonth = getDaysInMonth(currentYear, currentMonth);
await tag('DaysInCurrentMonth', daysInCurrentMonth);
console.log('9 DaysInCurrentMonth is: '+daysInCurrentMonth);
const daysInPreviousMonth = getDaysInMonth(currentYear, previousMonth);
await tag('DaysInPreviousMonth', daysInPreviousMonth);
console.log('10 DaysInPreviousMonth '+previousMonth +' is: '+daysInPreviousMonth);

var date = new Date();
date.setDate(date.getDate()-1);
const yesterDay = date.getDate();
await tag('YesterDay', yesterDay);
console.log('11 YesterDay is: ' +yesterDay);
const yesterDayMonth = date.getMonth() +1; // getMonth() returns month from 0 to 11
console.log('12 YesterDayMonth is: ' +yesterDayMonth);
await tag('YesterDayMonth', yesterDayMonth);
const yesterDayYear = date.getFullYear();
await tag('YesterDayYear', yesterDayYear);
console.log('13 YesterDayYear is: '+yesterDayYear);

var date = new Date();
date.setDate(date.getDate());

```

---

_[View the full topic](https://community.homey.app/t/app-pro-homeyscript/854)._
