Does anyone know why my datetimeadd formula is not giving me 8/31/2018 as the last day of the previous month? I can't figure this out!
(DateTimeAdd(DateTimeLastofMonth(), -1, "months")) is giving me 2018-08-30 23:59:59
Solved! Go to Solution.
Hi @IJH34!
This is happening because you are first getting the date/time of the last of this month (9-30-2018) and THEN subtracting one month, resulting in 8-30-2018.
@IJH34 To get the last day of the previous month, I tend to use this formula:
datetimeadd(DateTimeFirstOfMonth(),-1,"days")
This will get you the first day of the current month then subtracts one day to result in the last day of the previous month. Hope this helps!
Ah! So the best way to get the very last day regardless if its the 28th, 30th, or 31st would be DateTimeAdd(DateTimeFirstOfMonth(), -1, "Days")
Perfect! Thank you for your help.
I had the exact same issue going on. Thanks @Kenda for this, definitely what I was looking for!
Great! Glad you were able to find what you were looking for here 🙂
DateTimeTrim is also helpful to get the last day of the month:
DateTimeTrim(dt,t): Remove unwanted portions of a DateTime and return the modified DateTime
dt: DateTime data, expressed as a selected column or a specified DateTime value between quotes.
t: Trim type. Options include: