What is the Progress equivalent for Datediff syntax? - Forum - Community Groups - Progress Community

# What is the Progress equivalent for Datediff syntax?

Forum

#### What is the Progress equivalent for Datediff syntax?

• Hi All

I would like to know the progress equivalent for the following syntax

Datediff(PartTran.TranDate,Today) <365

Tried 'TIMESTAMPDIFF' but just can't get it right

This is to be used in a very simple 'IF' statement

If

Datediff(PartTran.TranDate,Today) <365

then yes

else No

I tried the following & they work fine, it is not until I try to define (Today '-365' Minus a number of days) that it fails

If

PartTran.TranDate = Today

then yes

Else No

If

PartTran.TranDate < Today

then yes

Else No

I apologise for this being so basic but I would appreciate any assistance

• On OpenEdge 10, check the INTERVAL function.

• if date1 - date2

• This worked perfectly

Thank You

• `maximmonin wrote:if date1 - date2 `

This isn't true when leap years are involved.

• Thanks Tim,

I have no need to be that specific however if you know how to accomodate leap year I would be interested for the future

Cheers Bill

• Interval is your preferred solution if you are on a sufficiently modern version of ABL.  Anything else is going to be a kludge.

Consulting in Model-Based Development, Transformation, and Object-Oriented Best Practice  http://www.cintegrity.com

• if you know how to accomodate leap year I would be interested for the future

One way of detecting leap years is to check the month of the day after February 28th.

Put this: (MONTH (DATE (2,28,iYear) + 1) = 2) into a function or a static helper class and your done:

DEFINE VARIABLE iYear AS INTEGER NO-UNDO.

DO iYear = 2000 TO 2020:

DISPL iYear "leap:" (MONTH (DATE (2,28,iYear) + 1) = 2) WITH DOWN .

DOWN .

END.

• Right ... there are ways to check and ways to imitate INTERVAL, but they are all doing something that is built in to the language in sufficiently modern versions so the real question becomes:

1) If you are using a sufficiently modern version, why not just use the function provided instead of messing around with alternatives.

2) If you aren't using a sufficiently modern version, why not?

3) If there is a really, really good answer to #2, then what can you do to compensate?

Consulting in Model-Based Development, Transformation, and Object-Oriented Best Practice  http://www.cintegrity.com

• How would you check for a leap year using the INTERVAL function? Ok, you could check for the number of days between the first of February and the first of March and compare that to 29.

Is that any better to checking the month of the day after February 28?

Can you PLEASE provide your code that you'd use to check for leap years?

• Can't provide any code until I know the problem to be solved.

• If you use INTERVAL, you don't need to check for leap year because it is built in.

Consulting in Model-Based Development, Transformation, and Object-Oriented Best Practice  http://www.cintegrity.com

• I can see a million use cases for knowing IF a year is a leap year - regardless if the platform does provide alternatives for calculating time spans... The OP clearly asked in his seconds question for a way to determine leap years. I'd rather believe he has a valid use case than questioning it just by principle.

• The OP did *not* mention leap year in the original question, but only after Tim pointed out that subtracting 365 was vulnerable to leap year.  INTERVAL is not vulnerable.

I don't dispute that one might want to know occasionally that a year was a leap year, but by and large, mostly one just wants to do some kind of date arithmetic and not have it do unexpected things because of leap years.  INTERVAL makes that test unnecessary.

Consulting in Model-Based Development, Transformation, and Object-Oriented Best Practice  http://www.cintegrity.com