blacksmithgu / obsidian-dataview Public
generated from obsidianmd/obsidian-sample-pluginThis issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to specify a format when displaying a date? #120
Comments
|
That would just be a great addition indeed! Preferrably in some format already known, like maybe the one "Templater" uses? Or simply It should also respect the locale Obsidian is set to, not just the system locale, like Templater does. For instance, when I set Obsidian to "English" on a German system, I get things like "Saturday" and "March" from Templater, but still "März" (March) from dataview. |
|
I use I think I might just look at how Templater handles it's dates and go from there. Will probably add a default global date format as a setting, as well as a format function like `dateformat(date, "<some format string/key/whatever>"). |
|
I second/third/fourth this, it would be great. Currently Instead of |
|
I'm doing this hack to keep it short and sweet |
|
I'd love to be able to select data output in ISO 8061 format. One use case: often I will cut-and-paste the output into other contexts (like a spreadsheet), and then ISO 8061 is really much more convenient for sorting the text. Plus, its unambiguous. |
|
This has gotten easier with the new It’d still be nice (and easier for many) if something like Maybe Luxon also offers this? |
|
Thanks for the reply, @Moonbase59, but I've never worked with |
|
Well, to get you primed, here’s your example translated to
For more, please consult the Docs, or check out my DataviewJS Snippet Showcase in the Obsidian Forums. Result:Code// default dateformat in case it’s forgotten in front matter
var dateformat = "YYYY-MM-DD";
if (dv.current().dateformat) { dateformat = dv.current().dateformat; }
// the table
// I used mtime & ctime instead of mday & cday, for better granularity.
dv.table(["File", "Last Modified", "Date Created"],
dv.pages()
.where(p => moment(p.file.mtime.toString()).isSame(dv.current().file.day.toString(), 'day') ||
moment(p.file.ctime.toString()).isSame(dv.current().file.day.toString(), 'day'))
.sort(p => p.file.mtime, 'asc')
.map(p => [
p.file.link,
moment(p.file.mtime.toString()).format(dateformat),
moment(p.file.ctime.toString()).format(dateformat),
])
);HTH, have fun! EDIT: Missed that you wanted files from the same day as the file’s date in the title, sorry. Updated, now using |
|
Are DataviewJS date comparisons not working? Ah, I guess they wouldn't, since it's using JavaScript comparisons. You can use |
|
Thanks so much to both of you! Integrating the simplification from @blacksmithgu, I've now got the following, which gets much just what I was looking for. ` |
|
This works well for ctime and mtime, but I can't get it to work for date type fields I have in my files. There doesn't seem to be a toString() for date type fields, and passing it directly into moment() results in today's date. Anyone can help? |
|
Hi there, I'm new to dataview and have no JS experience, so am a bit lost in this thread. I would like to get today's date (i.e., changing each day) in YYYY-MM-DD format, ideally as a one-liner. Currently I have Which outputs: How might I get this instead as Thank you, community! |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →

I might have missed this somewhere, but I can't find an option to specify a format when displaying a date. For example, when showing a field called
date-finishedthat holds an ISO-formatted date, I don't need the day of the week included. ShowingOct 3, 2020, for example, would be fine.Is it possible to specify the output format for a date somewhere?
The text was updated successfully, but these errors were encountered: