Replies: 2 comments 4 replies
-
|
What will a |
Beta Was this translation helpful? Give feedback.
-
|
Here are some comparisons on different DBs: Setup: -- create
CREATE TABLE EMPLOYEE (
empId INTEGER PRIMARY KEY,
from_datetime TIMESTAMP default NULL, -- DATETIME on sqlserver
to_datetime TIMESTAMP default NULL -- DATETIME on sqlserver
);
-- insert
INSERT INTO EMPLOYEE VALUES (0001, '2020-02-29 00:00:00', '2021-02-28 00:00:00');
INSERT INTO EMPLOYEE VALUES (0002, '2019-03-01 00:00:00', '2021-02-28 00:00:00');MySql: https://onecompiler.com/mysql/445mbpqqs SELECT empId, timestampdiff(month, from_datetime, to_datetime) as months, timestampdiff(day, from_datetime, to_datetime) as days FROM EMPLOYEE;
+-------+--------+------+
| empId | months | days |
+-------+--------+------+
| 1 | 11 | 365 |
| 2 | 23 | 730 |
+-------+--------+------+Postgress: https://onecompiler.com/postgresql/445m8rjn3 SELECT empId, extract(YEAR from age(to_datetime, from_datetime)) * 12 + extract(MONTH from age(to_datetime, from_datetime)) as months, (extract(epoch from (to_datetime - from_datetime)) / (60 * 60 * 24))::int as days
FROM EMPLOYEE;
empid | months | days
-------+--------+------
1 | 11 | 365
2 | 23 | 730SqlServer: https://onecompiler.com/sqlserver/445ma8vdv SELECT empId, datediff(month, from_datetime, to_datetime) as months, datediff(day, from_datetime, to_datetime) as days FROM EMPLOYEE;
empId months days
----------- ----------- -----------
1 12 365
2 23 730
Personally I think this is more of an issue on the usage than on the implementation. If your expected range is relatively small, (10^1, 10^2) and/or you require more accurate results for your use-case, you should maybe drop a unit or 2 and than perform your calculations. Let me know if you are OK with these results and if each technique is usable. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
first, thanks for this package @tpetry, I'm recently using this package in my project and looks great so far.
However I had to implement a
TimestampDifffunction for my use case, and was wondering if you wouldbe interested in having a look.
Would you be interested having such a function part of the package?
The one thing I'm confused is how to actually run and test the generated SQL per driver
and verify the result as I don't have much experience with PEST.
Beta Was this translation helpful? Give feedback.
All reactions