What is the Progress equivalent for Datediff syntax?

Posted by Admin on 28-Jul-2011 19:40

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

All Replies

Posted by Admin on 29-Jul-2011 01:36

On OpenEdge 10, check the INTERVAL function.

Posted by maximmonin on 29-Jul-2011 01:59

if date1 - date2

Posted by Admin on 31-Jul-2011 20:37

This worked perfectly

Thank You

Posted by Tim Kuehn on 03-Aug-2011 10:31

maximmonin wrote:

if date1 - date2

This isn't true when leap years are involved.

Posted by Admin on 04-Aug-2011 17:22

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

Posted by Thomas Mercer-Hursh on 04-Aug-2011 19:01

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

Posted by Admin on 04-Aug-2011 23:01

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.

Posted by Thomas Mercer-Hursh on 05-Aug-2011 00:39

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?

Posted by Admin on 05-Aug-2011 00:46

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?

Posted by gus on 05-Aug-2011 11:03

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

Posted by Thomas Mercer-Hursh on 05-Aug-2011 11:42

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

Posted by Admin on 05-Aug-2011 12:01

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.

Posted by Thomas Mercer-Hursh on 05-Aug-2011 12:14

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.

This thread is closed