Cast Date to Integer, like Delphi does.
Today I needed to convert a Delphi/Pascal code to Firebird PSQL. Part of the code used the integer value of a date to do some calcs. First, I tried to use Firebird CAST to convert a Date to Integer, but FB can’t do this type of cast (anyway, I’m not sure if the result would be the same as Delphi, since I don’t know what starting date Firebird uses for internal storage). So, the solution was to create a workaround and subtract the date from 30-December-1899 (Dublin Julian Day), ie:
my_int_var = current_date – cast(‘30.12.1899’ as date);
The above line will return the integer value of the today date, as Delphi/Pascal would do. In other words, it is the number of days since 30-Dec-1899.