36
Views
1
Comments
Solved
Identify if a DateTime is within the last 12 months from the Current DateTime
Application Type
Reactive

Hi Everyone,


I have a task that requires me to check whether the person's saved start DateTime in the DB is within the last 12 months from now (CurrDateTime). I'm having a hard time figuring out how to do that.


My thought is first, of course the person's start DateTime needs to be lesser than the CurrDateTime and probably the person's start DateTime a should be greater than the CurrDateTime minus a year. I initially thought of using the DiffDays function but I realized that may not be the best way since each month has different days. I looked for like, a "DiffYear" but I could not find one. So, I'd like to ask for your help.


Thanks in advance.


Regards,

Zack

2020-05-07 18-53-00
Rui Barradas
 
MVP
Solution

Hello there Reynald,

Hope you're doing well.

You can do something like this:

YourDateTime < CurrDateTime() and YourDateTime > AddYears(CurrDateTime(), -1)


It is indeed true that there is no DiffYear built-in function. But you can simulate it using AddYears and pass a negative number of years to add.


Hope that this helps you!


Kind regards,

Rui Barradas

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