0
Get Previous Month
Hi,
Hopefully a simple one. Im editing the body of when the email field is clicked.
Whats the syntax to get the previous month. I have tried everything with no luck.
Thanks
10 replies
-
I'm not sure what you want done.
A simple formula to get the previous month as a month name could look something like in a formula field:
let x := month(DateField) - 1; if x = 0 then "December" else monthName(x) end
I don't know if you are basing it off a date field or just using the current month.
-
To calculate a previous month you also need to allow for the fact that this might move the date to the December of the previous year. Use something like
let t := today(); let d := day(t); let m := month(t); let y := year(t); if m = 1 then m := 12; y := y - 1 else m := m - 1 end; date(y,m,d)
Use whatever field you need to in the first line.
Regards John
-
A mathematical alternative...
let t := today(); let d := day(t); let m := (12 + month(t) - 1) % 12; let y := year(t) - floor(m / 12); date(y,m,d)
-
Why not just use:
date(year(DateField), month(DateField) -1, day(DateField))
Content aside
- 2 yrs agoLast active
- 10Replies
- 197Views
-
4
Following