查询最近三天创建的文件

代码

Table file.ctime as "创建日期"
Where date(today) - file.ctime <= dur(3 day)
Sort file.ctime desc

image.png

结果

Table file.ctime as "创建日期"
Where date(today) - file.ctime <= dur(3 day)
Sort file.ctime desc

查询今日文章

代码

//【今日文章】获取
//获取当天创建的文件
const fileToday = new Date(dv.current().file.ctime);
console.log("fileToday", fileToday, "dv.current", dv.current().file.ctime)
 
const todayFileArray = dv.pages().where(file => {
    const fileDate = new Date(file.file.cday);
    console.log("Analyzing file:", file.file.path, "with creation date:", fileDate, "with fileToday", fileToday);
    return (fileDate.getDate() == fileToday.getDate() && fileDate.getMonth() == fileToday.getMonth() && fileDate.getFullYear() && fileToday.getFullYear());
})
console.log("Files created today:", todayFileArray.length);
if(todayFileArray.length > 0){
    dv.header("3","今日文章")
}
for(var i = 0;i<todayFileArray.length;i++){
    dv.el("li","[[ " + todayFileArray[i].file.path + "|"+todayFileArray[i].file.name+" ]]\n");
}

运行结果

//【今日文章】获取
//获取当天创建的文件
const fileToday = new Date(dv.current().file.ctime);
console.log("fileToday", fileToday, "dv.current", dv.current().file.ctime)
 
const todayFileArray = dv.pages().where(file => {
    const fileDate = new Date(file.file.cday);
    console.log("Analyzing file:", file.file.path, "with creation date:", fileDate, "with fileToday", fileToday);
    return (fileDate.getDate() == fileToday.getDate() && fileDate.getMonth() == fileToday.getMonth() && fileDate.getFullYear() && fileToday.getFullYear());
})
console.log("Files created today:", todayFileArray.length);
if(todayFileArray.length > 0){
    dv.header("3","今日文章")
}
for(var i = 0;i<todayFileArray.length;i++){
    dv.el("li","[[ " + todayFileArray[i].file.path + "|"+todayFileArray[i].file.name+" ]]\n");
}

查询本周新增的文件

代码

// 获取当前文件的创建日期
const currentFileCreateTime = dv.current().file.ctime;
const currentFileDate = new Date(currentFileCreateTime);
 
// 计算本周的第一天(星期一)和最后一天(星期日)
const startOfWeek = new Date(currentFileCreateTime);
startOfWeek.setDate(currentFileDate.getDate() - currentFileDate.getDay() + 1);
const endOfWeek = new Date(currentFileCreateTime);
endOfWeek.setDate(currentFileDate.getDate() - currentFileDate.getDay() + 7);
 
// 构建我的日记文件夹路径
const diaryFolder = "我的日记";
 
// 查找本周内的所有日记文件
const weeklyDiaries = dv.pages()
  .filter(page => page.file.path.startsWith(diaryFolder))
  .filter(page => {
    const pageDate = new Date(page.file.ctime);
    
    return pageDate >= startOfWeek && pageDate <= endOfWeek;
  });
 
// 输出本周的日记列表
for (const diary of weeklyDiaries) {
  dv.el("li", `[${diary.file.name}](${diary.file.path})`);
}

运行结果

// 获取当前文件的创建日期
const currentFileCreateTime = dv.current().file.ctime;
const currentFileDate = new Date(currentFileCreateTime);
 
// 计算本周的第一天(星期一)和最后一天(星期日)
const startOfWeek = new Date(currentFileCreateTime);
startOfWeek.setDate(currentFileDate.getDate() - currentFileDate.getDay() + 1);
const endOfWeek = new Date(currentFileCreateTime);
endOfWeek.setDate(currentFileDate.getDate() - currentFileDate.getDay() + 7);
 
// 构建我的日记文件夹路径
const diaryFolder = "我的日记";
 
// 查找本周内的所有日记文件
const weeklyDiaries = dv.pages()
  .filter(page => page.file.path.startsWith(diaryFolder))
  .filter(page => {
    const pageDate = new Date(page.file.ctime);
    
    return pageDate >= startOfWeek && pageDate <= endOfWeek;
  });
 
// 输出本周的日记列表
for (const diary of weeklyDiaries) {
  dv.el("li", `[${diary.file.name}](${diary.file.path})`);
}