Obsidian New Year Countdown
Obsidian New Year Countdown
New Year Countdown in Obsidian with DataviewJS
As we approach the end of the year, add some excitement to your Obsidian vault with a New Year Countdown. Using DataviewJS and moment.js
, you can create a countdown timer that shows the remaining days, hours, and minutes until New Year’s Day.
Here’s the code for the New Year Countdown:
1
2
3
4
5
6
7
8
9
10
```dataviewjs
// New Year Countdown
const today = moment();
const newYear = moment(`${today.year() + 1}-01-01`, "YYYY-MM-DD");
const daysToNewYear = newYear.diff(today, 'days');
const hoursToNewYear = newYear.diff(today, 'hours') % 24;
const minutesToNewYear = newYear.diff(today, 'minutes') % 60;
const newYearContainer = this.container;
newYearContainer.createEl("h1", { text: `🎉 Countdown to New Year 🎆` });
newYearContainer.createEl("p", { text: `${daysToNewYear} days, ${hoursToNewYear} hours, and ${minutesToNewYear} minutes left!` });
New Year Countdown Script Explanation
This script calculates how much time is left until the New Year and displays it in a neat format. The countdown updates in real time, keeping your notes dynamic and engaging.
How It Works:
- Set the Date: The script sets the target date for New Year’s Day, which is always January 1 of the next year.
- Calculate Time Difference: It calculates the days, hours, and minutes remaining.
- Display the Countdown: The script creates two elements in your Obsidian note — a heading (
h1
) and a paragraph (p
) — to display the remaining time.
Why Use This?
- Real-time Countdown: The countdown dynamically adjusts based on the current date, ensuring accuracy.
- Fun Addition: It’s a fun way to add an interactive element to your notes.
- Customization: You can adapt the script to count down to other special dates or milestones.
Give it a try, and start the countdown to a fantastic New Year! 🎇
This post is licensed under
CC BY 4.0
by the author.