Dataview sorting by creation date

Things I have tried

Sorting both by DESC and ASC
Double-checked the dates in Finder

I want a simple list. I also tried making it a table view with creation date as a column.

table file.cdate AS "Created time" 
FROM "Life"
sort file.cdate DESC```

As you can see, there’s no data in that column.

What I’m trying to do

Sort my list of files in a folder by creation date.

This is the order they are presented in the live view in Obsidian. They look to be sorted by filename rather than date.

list FROM "Life"
sort file.cdate ASC

You’re very close! This query worked for me (my pages are in a folder called “Notes”):

TABLE file.ctime as "Created"
FROM "Notes"
SORT file.ctime DESC

You can see a list of all the date fields here:


Thanks! I can now see the file creation time in my table but it’s still not sorting at all.

table file.ctime as "Created"  
FROM "Life"
sort file.ctime DESC```
1 Like

That’s very strange! That same query runs correctly in my vault, sorting the files by newest to oldest.

I don’t know why it would sort incorrectly for you. Perhaps Dataview’s cache is out of date? Maybe try closing and opening Obsidian and see if that fixes it?

Quitting and reopening obsidian did something but still didn’t fix it. This is the sort that was generated from the following code. I don’t get it.

table file.cday as "Created"  
FROM "Life"
sort file.ctime DESC```

Disable all others plugins, restart obsidian and check again dataview results.

Good thought. No dice, though.

Same syntax, different sort this time. I don’t know what’s going on.

I’m flummoxed. My only guess is that there is something funny going on with create date on your OS.

Maybe try using mday/mtime instead of cday/ctime? I know it’s not what you’re trying to do, but it might give us a clue as to what’s going on.

The Finder and the Obsidian file explorer match up when sorted the same way. It’s just data view that’s screwing up. I really have no clue what’s happening!

I’m going to try on another folder, using the same file names and creation order and see if that fixes it.

Ok. Some progress. On a newly created folder, with the same exact filenames and creation order (not dates, obviously), the sort is correct. TBH, the date the files were created isn’t important, just the order so I may just copy the contents to the newly created files and call it a day. But such a weird bug to encounter!

One test.

Create a new file and check any of these inline queries:





I’ll try that. In the meantime, I encountered something interesting.

When in live view, dataview shows my table but when I got to preview mode or whatever it’s called this shows up:

Dataview: Error: 
-- PARSING FAILED --------------------------------------------------

  1 | table file.cday as "Created"  
  2 | FROM "Life"
> 3 | sort file.ctime DESC```
    |                     ^
  4 | 
  5 | 

Expected one of the following: 

',', /FLATTEN/i, /FROM/i, /GROUP BY/i, /LIMIT/i, /SORT/i, /WHERE/i, EOF

I didn’t think anything of it but when I created my new test folder, the preview mode doesn’t throw those errors. Any idea why dataview would fail on that particular folder?

More weirdness.

When using the file I have been using for the list, I get the problem. But when using the newly created file in my newly created folder but having it point to my original “Life” folder, it works.

You can’t end your code block in that way!

table file.ctime as "Created"  
FROM "Life"
sort file.ctime DESC

The three backticks at the end need to be alone in the last line.

Don’t tell us that all these issues were caused by this very basic error!

1 Like

And, as always with my attempts at coding, it’s a dumb error that causes it. :laughing:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.