How to change the date? #2
-
I love the plugin, but can you give an example of how to change the file name date format? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 11 replies
-
thanks, you could probably use something like the example below, but havent tested it: dv.span("**Alcohol**")
const calendarData = {
year: 2022,
colors: { // optional, defaults to green
orange: ["#ffa244","#fd7f00","#dd6f00","#bf6000","#9b4e00"],
pink: ["#ff96cb","#ff70b8","#ff3a9d","#ee0077","#c30062"]
},
entries: [] // populated in the DataviewJS loop below
}
for(let page of dv.pages('"Journal"').where(p=>p.alcohol).sort(p=>p.file.name)){
const date = new Date(page.file.name);
const yyyy = date.getFullYear();
let mm = date.getMonth() + 1; // Months start at 0!
let dd = date.getDate();
if (dd < 10) dd = '0' + dd;
if (mm < 10) mm = '0' + mm;
const formattedDate = yyyy + "-" + mm + '-' + dd;
calendarData.entries.push({
date: formattedDate,
intensity: page.alcohol
})
}
renderHeatmapCalendar(this.container, calendarData) |
Beta Was this translation helpful? Give feedback.
-
This formatted date works thank you! The only problem I have is it's not showing the color I want it to show. For example I want to track a habit where I track the amount of pages I read everyday from 1 to let's say 20. how do you intensify a color? Any tips will be helpful :) |
Beta Was this translation helpful? Give feedback.
-
Hi there, I have a similar issue to @wesleyboers but am struggling to make it work. My daily notes are formatted in the form "dddd, MMMM Do YYYY" ("Wednesday, November 16th 2022").
Is the problem that getMonth(), getDate() etc. aren't working in this case of date format? |
Beta Was this translation helpful? Give feedback.
-
FYI another solution is to get the date from the file creation date property independently of the file name: let month = page.file.cday.month <= 10 ? "0"+page.file.cday.month : page.file.cday.month;
let day = page.file.cday.day <= 10 ? "0"+page.file.cday.day : page.file.cday.day;
let date = page.file.cday.year+"-"+month+"-"+day |
Beta Was this translation helpful? Give feedback.
-
Damn! my daily note format is "YYYY-MM-DD ddd", (so today is 2024-01-03 Wed) is there a way to change it to make it work? |
Beta Was this translation helpful? Give feedback.
-
For those who use some kind of //DataviewJS loop
for (let page of dv.pages()
.where(p => p.file.path.contains("MY_FOLDER"))) {
var filedate = page.date;
var date = new Date(filedate);
try{
let format = date.toISOString().split('T')[0]
calendarData.entries.push({
date: format, // (required) Format YYYY-MM-DD
})
} catch (error) {
dv.span("<br/>" + error + " [[" + page.file.name + "]]") // uncomment for troubleshooting
console.error(error);
}
} |
Beta Was this translation helpful? Give feedback.
thanks, you could probably use something like the example below, but havent tested it: