# How to show the last day of the previous month

I’m working on making a “dial” on the side of the watch face that shows the cutout of the day - month.

As of now, I have most of it working, but a small issue pops up when the current day is the first of the month. The issue is the previous day will show up as a zero. (I have it coded as ([DAY_1_31]-1) which works for all but the first day)

Ideally, I’d like it to display the last day of the previous month. So instead of a zero it would show 28(29), 30, or 31 depending on what the last day of the month was for the previous month. I’ve been digging through the forum and cant seem to find anything around that. I’m also not sure if it’s possible to get that value from the Unix date either.

You may need to do it with if else tag expressions
E.g ( (([DAY]-1) ==0) * (((([MON]-1)==1)*31)) + (([DAY]-1) ==0) * ((([MON]-1)==3)*31)) + (([DAY]-1) ==0) * ((([MON]-1)==4)*30)) …) + (([DAY]-1>0) * ([DAY] - 1)))

And so on… not sure the calculation for feb(leaps yr)
You have to add conditions tag for when ([MON] - 1==2)

Via caculating if leap yr a not

Sudo code:
if day is 1st day of the month. Take month subtract one and display the end date of that month.
E.g if today is 1st feb then = if 2 - 1 = 1(jan) then it be 31

And so on.

If day is not 1st day of the month. Do your day - 1

Mind the “(” i may have open and close errorly.

Read from logical expression on wards

1 Like

@WxmanGary leap yr caculation

So in sudo code.

If day == 1 and (year%4 == 0) and if (mon - 1 == 2) then 29 else 28

1 Like

This is the long line of code I got to work

(([DAY_1_31])-1==0? ((([DAY_1_31]-1)==0)*((([MON]-1)==0)31))+((([DAY_1_31]-1)==0)((([MON]-1)==1)31))+((([YEAR]%4)==0? (([DAY_1_31]-1)==0)((([MON]-1)==2)29):((([DAY_1_31]-1)==0)((([MON]-1)==2)28))))+((([DAY_1_31]-1)==0)((([MON]-1)==3)31))+((([DAY_1_31]-1)==0)((([MON]-1)==4)30))+((([DAY_1_31]-1)==0)((([MON]-1)==5)31))+((([DAY_1_31]-1)==0)((([MON]-1)==6)30))+((([DAY_1_31]-1)==0)((([MON]-1)==7)31))+((([DAY_1_31]-1)==0)((([MON]-1)==8)31))+((([DAY_1_31]-1)==0)((([MON]-1)==9)30))+((([DAY_1_31]-1)==0)((([MON]-1)==10)31))+((([DAY_1_31]-1)==0)((([MON]-1)==11)30))+((([DAY_1_31]-1)==0)((([MON]-1)==12)*31)):[DAY_1_31]-1)

Thank you so much for pointing me in the correct direction!!

Here’s how that looks in the watch
(March 1st 2023)

(March 1st 2024)

2 Likes

Nice, that is pretty long formula. I was trying to derive similar earlier for a calendar purpose, but lost patience. Glad you managed to make it work.

Btw. when you are mimicking a mechanical date ring, it has always 31 before 1 and after shorter months it just skips to 1 (or is manually corrected).

Hi, i found a way to shorten the formula. Clue is

In discriptive form (sudo)

If (mon - 1 ) if its equals to 1 the day is 31
Else
If (mon - 1) is between 3 and 7 inclusive and mod 2 is 0 its 30 if mod 2 is not 0 its 31 days

If (mon - 1) is between 8 and 12 inclusive and mod 2 is 0 its 31 if mod 2 is not 0 its 30

If mon-1 is 2 do leap yr caculation as usual

U mean u want to see 31 before 1 in your version calender?

Different from orignal post version?

@WxmanGary is it ok i answer peter question? Here though it slightly different case

It was just remark about my observation, not a question. I know how to mimic real date ring (even if not using one at all), its much easier than to calculate the previous and following date of actual months.

I see @Peter,

Actually u are right just need to have a ring with all the numbers 1 to 31 (space properly) and rotate to the angle that display the date in the cutout.

Alternatively u could instead of caculate like what i explained earlier @WxmanGary u could mimick peter observations by setting your previous date to 31 if day - 1 = 0

That is the text field displaying previous day

([DAY-1]==0)? 31 : ([DAY-1])

Then for text field
After current date
([DAY+1]==32)? 1 : ([DAY]+1)

@WxmanGary
Sorry didnt think of this earlier, was just answering as what your topic was titled

1 Like