![Sune_Theodorsen Sune_Theodorsen](https://community.airtable.com/legacyfs/online/avatars/2X/6/66f48bbca3f78d7ee84438721844676f5c3f71fd.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 19, 2018 09:40 AM
Hi,
I’m trying to make a formula that gives me the last day of the current month. So, while we’re in March I want it to return 31 or 2018-03-31 and when we get to April return 30 or 2018-04-30.
It seems pretty simple in JS (https://stackoverflow.com/questions/1184334/get-number-days-in-a-specified-month-using-javascript) - but don’t know how to do it on Airtable.
Any ideas?
Thanks a lot!
Best
Sune
![Elias_Gomez_Sai Elias_Gomez_Sai](https://community.airtable.com/legacyfs/online/avatars/2X/f/fab55282357df990cbdd5855169d11a2c6644b0d.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 20, 2018 03:44 PM
Try this formula:
DATETIME_DIFF(DATETIME_PARSE("1-"&CONCATENATE(MONTH(TODAY())+1)&"-"&YEAR(TODAY()),"D-M-YYYY"), DATETIME_PARSE("1-"&MONTH(TODAY())&"-"&YEAR(TODAY()),"D-M-YYYY"),"d")
You can explore it here: https://airtable.com/shrXEpPCnjcgCm76n
- You could pass a Date instead of using
TODAY()
- I had to use
CONCATENATE()
to convert the Next Month to a string
![Sune_Theodorsen Sune_Theodorsen](https://community.airtable.com/legacyfs/online/avatars/2X/6/66f48bbca3f78d7ee84438721844676f5c3f71fd.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 21, 2018 01:11 AM
Works perfectly - thanks a lot Elias!
![Tech_Tylercivic Tech_Tylercivic](https://community.airtable.com/legacyfs/online/avatars/1X/6228332b3b062017a6652419c5ab39a620c6c508.jpeg)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 21, 2018 07:55 AM
Couldn’t you just have a 12 row table and look it up?
![Workshop_Team Workshop_Team](https://community.airtable.com/legacyfs/online/avatars/2X/f/f4a2d7ffdb7b0a8659be28e80857d3a148b190fd.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sep 06, 2018 09:16 PM
Much after the topic, but for those who come here looking for an answer this is simple and would work too:
DAY(DATEADD(DATEADD(DATETIME_FORMAT(TODAY(),‘YYYY-MM’),1,‘month’),-1,‘days’))
![Mike_Johnston Mike_Johnston](https://community.airtable.com/legacyfs/online/avatars/2X/4/44789be2735232eebf9b493b2ac746280c108613.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 22, 2020 06:17 PM
Hi @Elias_Gomez_Sainz, thanks for your formula! Does the formula work with dates in the month of December? I can get it to work with all other months except when I pass it a Dec date. Curious if others are seeing it work with Dec dates. Thanks
![kuovonne kuovonne](https://community.airtable.com/legacyfs/online/avatars/3X/b/c/bcecb2d58f8302e9d9f520621c02ff41be54488c.jpeg)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 22, 2020 09:22 PM
Workshop_Team’s formula works well, but you have to convert the curly quotes to straight quotes:
DAY(
DATEADD(
DATEADD(
DATETIME_FORMAT(YEAR({date}) & "-" & MONTH({date}) ,"YYYY-MM"),
1,
"months"
),
-1,
"days"
)
)
Or you could try this formula:
SWITCH(MONTH({date}),
1, 31,
2, IF(MOD(YEAR({date}), 400) = 0,
29,
IF(MOD(YEAR({date}), 100) = 0,
28,
IF(MOD(YEAR({date}), 4) = 0,
29,
28
)
)
),
3, 31,
4, 30,
5, 31,
6, 30,
7, 31,
8, 31,
9, 30,
10, 31,
11, 30,
12, 31
)
![Mike_Johnston Mike_Johnston](https://community.airtable.com/legacyfs/online/avatars/2X/4/44789be2735232eebf9b493b2ac746280c108613.png)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 25, 2020 02:05 PM
Nice work @kuovonne. Thanks!
![Vernon_Fowler Vernon_Fowler](https://community.airtable.com/legacyfs/online/avatars/3X/9/6/9614b9baffdc8d603aa2654a88e4398a6e09d941.jpeg)
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dec 14, 2020 02:13 PM
Thank you @kuovonne - the switch function version works in December, each leap year, and is clear and easy to read and understand. :slightly_smiling_face: :grinning:
![](/skins/images/75AB00B4920FD2D67A8CABF77C9DECC4/responsive_peak/images/icon_anonymous_message.png)