In a PSQL module that I’m using in Invantive Cloud to export account and item data to a .csv file, I’d like to retrieve only the rows where Modified equals today. Comparing this column with sysdate or GETDATE() should work, but both the GETDATE() function and the Modified column in Exact Online include both a date and a time component.
By using Date(modified) I’d expect to get only the date component, but that’s not the case.
What would be the best way to compare these dates with each other?
Het meest efficient is om de vergelijking zo te maken dat server-side filtering en indexen gebruikt kunnen worden. Dit kan bijvoorbeeld met:
select ...
from exactonlinerest..items
where modified >= trunc(sysdate)
and modified < trunc(sysdate ) + 1
Merk op dat sysdate uitgedrukt wordt in de tijdzone van de Invantive Cloud-server (Ierland), maar bij een on-premises installatie van Query Tool is de daar lokale tijd.
Sysdateutc is altijd in UTC (Z), onafhankelijk van de locatie.
Bij Exact Online kan of het filter wat breder gemaakt worden (als dat past bij het doel), of opgevraagd met bijvoorbeeld:
select ServerTime
, ServerUtcOffset
from me
De ServerUtcOffset in seconden kan gecorrigeerd worden boven op sysdateutc door hem er bij op te tellen na deling door 86400.
Maar in alle gevallen geldt dat er altijd meerdere seconden of minuten verschil kunnen zijn tussen verschillende servers, ondanks NTP en andere mechanismen. Hou hiermee rekening in het filter.