Working with dates
Application Type
Traditional Web

Hi. Hope everyone is great. I'm building an "if" condition to a button which will navigate to page "x" or "y" based on the condition.   

The condition will be for it to compare todays date with the date i have in my entity table. If the date in the table is within the last 6 months it will go to page "x" if the date in the table was longer ago than 6 months it will go to page "y"   

not all months have equal days so I understand it may not be exactly 6 months all of the time, im not concerned about that. 

If someone can be me an example of how to donthis it would be much appreciated.

Thank you,

Mike

mvp_badge
MVP
Solution

Hello there Michael,

Hope you're doing well.


So you have today's date:

CurrDate()

And you can easily calculate today's date minus 6 months:

AddMonths(CurrDate(), -6)


So you just need to do a query to your database in order to fetch that date. And then verify if that date is between this interval:

YourDatabaseDate <= CurrDate() and YourDatabaseDate >= AddMonths(CurrDate(), -6)


So if the condition above is True, it means that the date is between today and the last 6 months, so you redirect to page "X", otherwise you go to page "Y".


Hope that this helps you!


Kind regards,

Rui Barradas

Thank you Rui, I tried something similar but only had half of the condition you mentioned. I've tried yours, which makes perfect sense but its still not working. The only thing I have to do different is add in a conversion so my condition reads like this:

MyTableDate <= DateToText(CurrDate()) and MyTableDate >= DateToText(AddMonths(CurrDate(), -6))

The condition is correct as in there are no errors, but its not doing what I need it to do, perhaps I have a formatting issue somewhere. 

Thank you Rui

mvp_badge
MVP

Hello Michael,

Maybe you can try to do a debug just to see if the values are correct by the time the condition is beeing evaluated.

Can you please verify?


Kind regards,

Rui Barradas

Update, just to test, I removed the 2nd half of the condition and it went to the correct page. When I add in the second half it goes to the wrong page. 

mvp_badge
MVP

If you remove the 2nd half of the condition, you will just check if the date is in the past. Be careful, if your database date is longer than 6 months (for example, 10 months), it will redirect to a wrong page.

It works, the problem wasn't anything g to do with the condition. I spotted a mistake within my table preparation which meant it wasn't pulling back the data correctly in the preperation which in turn meant that the condition didn't know what to do. 

Thanks for your help Rui, have a great day.

Hi Michael,

maybe you should do the other way, convert from your table to a date field and not the way you said.

TextToDate(MyTableDate)  >= AddMonths(CurrDate(), -6)  and TextToDate(MyTableDate)  <= CurrDate()

Regards

Hi Carl, this makes sense to me too but it doesn't allow me to use the < or > operators to date values so had to do it the other way. As it happens, it turns out the problem was actually to do with the the way I was building the table in my preparation. Its all working now, thank you for your help.

Mike.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.