How to rewrite this query from PostgreSQL in Clarion?
select extract(epoch from (timestamp '02-01-2021 06:00' - timestamp '01-01-2021 22:00'))/3600 as interval_as_hours_numeric
How to rewrite this query from PostgreSQL in Clarion?
select extract(epoch from (timestamp '02-01-2021 06:00' - timestamp '01-01-2021 22:00'))/3600 as interval_as_hours_numeric
Copyright © 2021 Jogjafile Inc.
When you ask "How to rewrite select extract(epoch from (timestamp '02-01-2021 06:00' - timestamp '01-01-2021 22:00'))/3600 as interval_as_hours_numeric" in Clarion, I'm assuming you mean do the date/time math using Clarion syntax.
If you want to use this query via the Clarion file drivers and send it to PostgreSQL, you can use this code:
The result will be in the first field in the mySQLtable record structure.
However, I suspect that isn't what you wanted, so I'll continue as if you wanted to do this with Clarion syntax. I will also assume you're relatively new to Clarion, so I may explain things you already know.
Clarion does not have a timestamp data type. It supports DATE and TIME. It also supports SQL DATETIME types indirectly by combining the DATE and TIME data types using a GROUP() and an OVER(). Any combination of the DATE and TIME must be managed by the dev using tactics of this nature. As a result, the timestamp's date and time portions must be parsed separately.
In Clarion, you can parse date and time values by hand or via the Clarion DEFORMAT() verb. I do this by hand in a class method so that I don't have to worry about DEFORMAT behavior changes in the future. To keep it simple, we'll use DEFORMAT().
There are other (better) ways to do this, but this provides what you need in the form of an explanation rather than a perhaps more obtuse class method that might not explain WHY the code does what it does.
Some sample code...