Date plus 1 and minus 1

Hi again team,

I am looking to display the date minus and plus one, however on the regardless of the month chosen when the date is 1, the date minus 1 is showing as 31 and date plus 1 is showing as 31 (which is incorrect for Feb for example). When the date is 31 it is showing date plus one as 32 which is obvs incorrect too.

I am also finding the above does not work/show the result with tag [DAY_1_31_Z] either, only DAY_1_31].

Anyone got a workaround or any advice? Tried searching the forum and ([DAY_1_31]==1?31:[DAY_1_31]+1) which renders the above results.

Thanks.

([DAY_1_31]==31?1:[DAY_1_31]+1)

And

([DAY_1_31]==1?31:[DAY_1_31]-1)

Actually what u trying to do…there may be easier ways to get what u want

Thanks @Knightwing however the +1 you shared only works for months with 31 days (and therefore shows 1), however for Feb 2024 when the date is showing 29 the +1 date is showing 30, rather than 1 which is the next date.

Similarly the -1 tag when the date is 1st March 2024 is showing 31 when it should be 29 for Feb.

On both these also when using [DAY_1_31_Z] it breaks the formula. Ideally need a leading zero on this otherwise the design will look silly.

I have looked at the thread provided and used long tag contained and it doesn’t work. Any ideas @WxmanGary how I could get this working?

HI, maybe that long code needs some fine tunning.
@WxmanGary it seems for example 1st day of month - 1 the number disappears.
can you post what you have now ?

but @jsmith88 if you look trough the whole thread you do not need it to be in the way you describe.

as this is how the real analog calender disk works it such a way it has 1 to 31
so if at 1st day of the month the previous number on the disk is always 31. and the day after 31 will always be 1

@jsmith88

i solved the long code, rename the zip to .wfs
to open.

date_minus.zip (156.7 KB)

the reason is cut and pasting that long code directly cause some * to be missing from the code
anyway i fixed it and store it in the WFS i posted.

Legend, thank you @Knightwing that works perfectly for date -1, now I am just trying to understand how to adapt for date +1, playing around with it as we speak, thinking something along the lines of dividing by the days in the month (instead of *) and adding 1 at the end (instead of 1) although that may be complete rubbish! Got any advice?

Also, I have updated the code to use [DAY_1_31_Z] instead of [DAY_1_31] to show the leading 0 and it breaks, any advice on showing a leading 0 on these?

Hi, in the formula * means && in a if statement, and + if its 2 tanary formula its a or

So

E.g

([DAY]==1)*([DAY]==2)
means
If ([DAY]==1)&&([DAY]==2)

And

([DAY]==1)+([DAY]==2)

Means
If ([DAY]==1) or ([DAY]==2)

That the basic of tanary function.

Anyway to do plus one

Is figure out which month are 30 days
And which months are 31 days

Then if day is the last day = 1 else +1

And leap yrs are year%4

Thanks for the further advice @Knightwing I’m really trying to get my head around it, so I am thinking that the Day fields need the ‘-1’ removed, then the last ‘else’ should just be ‘1’:

(([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)

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

Actually that hasn’t worked, might need to sleep on it!

You can also do this using 4 images that you move to show numbers
use one image for months with 31 days one for 30 day two for February
You just position it under “windows” by the day of the month.

Ron
Samsung Developer Relations

1 Like

Hold on, the else needs to be day+1 at the end, just need to work out how to do the 'show 1 if its the last day of the given month…

Cheers Ron its a good shout, I might resort to this if I can’t work out making it live copy

Basic formula to see which months are 30/ 31/28 / 29 days

((([MON])>=1)*([MON]<=7))?

(([MON]%2==0)?30:31):

((([MON])>=8)*([MON]<=12))?

(([MON]%2==0)?31:30):

(([YEAR]%4)==0)?29:28)))

Replace 31,30,29,28

With additional formula if u +1 or -1 to those date

Or use ron method

Hi @Knightwing thanks for the additional guidance, I have been playing with all this for over 2 hours now and just can’t get my head around showing 1 where it is the last day in the previous month, is there any way you could provide that to me. I’d obviously love to work it out for myself but I seem to be confusing myself and going around in circles…

Once I have this working I am thinking I might start a thread where members can post the useful tags, watch-outs and advice they have gained along their way as I have loads of little bits I have picked up throughout that other people will find super useful.

Its possible but i dont have much time on my side to type the formula, i can only guide u…through it…or correct u where u are wrong. Best to post what u have done here.

The wfs…rename it to zip…

Edit:

((([MON]-1)==1)?31:

((([MON]-1)>=3)*(([MON]-1)<=7))?

((([MON-1])%2==0)?30:31):(((([MON]-1)>=8)*(([MON]-1)<=12))?

((([MON-1])%2==0)?31:30):

(([YEAR]%4)==0)?29:28)))

[MON]-1 ( IF MINUS 1)
[MON] (if add one)

Not to worry @Knightwing I have managed to work it out by breaking it down one month at a time then going back to adjust Feb for leap years, result is the below working:

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

Thanks for your tips, I am going to start a community thread now for little nuggets like these!

1 Like

Hi, not same as my…but if it works it works

The idea is similar. Know which months has 30, 31 ,29 or 28

And work from there.

For shorter code

Remember month 1

Is 31 days

Month 3 to 7 inclusive
If the month number is %2 (even numbers) == 0 its 30 days
Else 31 days

For months 8 to 12 inclusive
%2 == 0 (even numbers)
Its 31 days else 30 days

And for month 2 leap years is 29 days else 28 days

Hope this helps you and others in future

Hello,
this forum uses the * as marks for bold or slanted formating, so it is advisable to put formulas containing muliple multiplication signs into the preformated text tags.

1 Like

Hi, reposting the formula for @jsmith88

Formula to -1 to date

(([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)

For easy copy and paste

(([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)

Formula to + 1 to date

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

For easy copy and paste

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

Reformated the formula to display * properly

1 Like

Hi, @Peter and @jsmith88

Anyother way is to escape the * with \ so
Type \* to display * in your post properly

@jsmith88 I manage to do the shorten version of your question.