# Dataview Date Formatting

**URL:** <https://forum.obsidian.md/t/dataview-date-formatting/37456>\
**Category:** Help\
**Tags:** dataview\
**Created:** [May 13, 2022, 10:05pm UTC](https://forum.obsidian.md/t/dataview-date-formatting/37456 "2022-05-13T22:05:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwhiii](https://forum.obsidian.md/user_avatar/forum.obsidian.md/cwhiii/32/23960_2.png) [@cwhiii](https://forum.obsidian.md/u/cwhiii)\
**Post date:** [May 13, 2022, 10:05pm UTC](https://forum.obsidian.md/t/dataview-date-formatting/37456/1 "2022-05-13T22:05:31Z")

</div>

### What I’m trying to do

I have a dataview as follows:

```dataview
TABLE 
	dateOfPurchase
	FROM #InventoryItem
	WHERE file.name = "Air Pump"
	SORT file.name asc

```

The file Air Pump looks like this:

```auto
dateOfPurchase:: 2021-09-10
#InventoryItem

```

So far, so good. However, when the dataview is rendered, it changes the date format to “September 10, 2021”. This makes the date too long, and breaks each row into multiple lines.

I’ve attempted to use several formatting ways, such as:

- dateFormat(dateOfPurchase, “YYYY-MM-dd”)
- date(file.day, “YYYY-MM-dd”)
- date(dateOfPurchase, “YYYY-MM-dd”)
- Etc.

I’ve scoured the [Dataview documentation](https://blacksmithgu.github.io/obsidian-dataview/query/functions/), searched these forums, and googled this.

However, no matter what I’ve tried, the date always displays as “September 10, 2021”.

Is there any way to apply a date format to a date shown in a dataview? I’m trying to get it to display as either of:

- 2021-Sep-10
- 2021-09-10

---

<div class="post-metadata">

**Author:** ![mnvwvnm](https://forum.obsidian.md/user_avatar/forum.obsidian.md/mnvwvnm/32/9766_2.png) [@mnvwvnm](https://forum.obsidian.md/u/mnvwvnm)\
**Post date:** [May 13, 2022, 10:19pm UTC](https://forum.obsidian.md/t/dataview-date-formatting/37456/2 "2022-05-13T22:19:25Z")

</div>

Hi!

You have to options:

1 - if you want to apply a specific format to all your date outputs, go to settings \> dataview and change the output date format using luxon tokens.

 ![image](https://forum.obsidian.md/uploads/default/original/3X/0/a/0ae4a91ef6968abeafc374f6639cad2c35bc7780.png)

2 - if you want to change a specific output in the query, use the function `dateformat(field, "yyyy-MM-dd")` and use the luxon tokens.

For example, for the format “2021-09-10” use

```java
dateformat(dateofpurchase, "yyyy-MM-dd")

```

… for “2021-Sep-10” use:

```auto
dateformat(dateofpurchase, "yyyy-LLL-dd")

```

Luxon tokens: [luxon/formatting.md at master · moment/luxon · GitHub](https://github.com/moment/luxon/blob/master/docs/formatting.md)

---

<div class="post-metadata">

**Author:** ![cwhiii](https://forum.obsidian.md/user_avatar/forum.obsidian.md/cwhiii/32/23960_2.png) [@cwhiii](https://forum.obsidian.md/u/cwhiii)\
**Post date:** [May 19, 2022, 1:30pm UTC](https://forum.obsidian.md/t/dataview-date-formatting/37456/3 "2022-05-19T13:30:27Z")

</div>

Thanks! While option #2 continues to not work for me, option #1 did the trick.

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [May 26, 2022, 1:30pm UTC](https://forum.obsidian.md/t/dataview-date-formatting/37456/4 "2022-05-26T13:30:29Z")

</div>

Closed on May 26, 2022, 1:30pm UTC

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