Skip to content
Advertisement

Query recent records with separate date and time fields

I’m working with a table in SAP Advantage with separate date and time fields. I want to find records with a date and time within the last 5 minutes.

This works 99% of the time:

However, this won’t work around midnight. For instance, at 12:00AM, any records created at 11:57PM the previous day won’t match the filter.

Any idea to do this? Thanks!

Sample image of data. Based on this data, at 7/12/19 at 12:01AM, I’d like to return the last 2 rows.

enter image description here

Advertisement

Answer

The easiest way is to recombine the fields and then use TIMESTAMPDIFF():

Which gives the expected result of:

It would be even more trivial if ADS supported an operator or a function to directly combine a date and a time, but I can’t find one in the documentation.

So if you integrate that into your original SQL code, it would be:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement