I’m working on a PHP project with Firebird, about working hours. Basically, every worker has a card, which he stamps on entering and leaving the building. Each stamp is recorded into the ARCHIVE table, with date (DATUM), id (NREC) and user_id (NCODE). What I have to do is get the last and first time of each day, and calculate hours. So to get the first and last, I used this:
SELECT MAX(NREC)
FROM ARCHIVE
WHERE DATUM BETWEEN '$day.$month.$year' AND '$day+1.$month.$year';
SELECT MIN(NREC)
FROM ARCHIVE
WHERE DATUM BETWEEN '$day.$month.$year' AND '$day+1.$month.$year';
I save both max and max in a variable, then I select the both dates and calculate. But that are 4 queries. Is there any simpler/easier way?
Also, DATUM is a timestamp
Could try:
If Firebird works anything like MySQL this should give you two timestamps.