![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi all, I am trying to get a portable SQL statement that returns the difference between 2 dates as a number of seconds. Is there any possibility to use standard SQL functions to achieve this? In PostgreSQL one can use: extract(epoch from (date1 - date2)) In MySQL one can use: datediff(date1,date2) * 86400 In Access one can use: DateDiff("s",date1,date2) etc... None of the above pleases me - I'ld like a common expression for all these databases. Regards, Johan |
#3
| |||
| |||
|
|
I am trying to get a portable SQL statement that returns the difference between 2 dates as a number of seconds. Is there any possibility to use standard SQL functions to achieve this? In PostgreSQL one can use: extract(epoch from (date1 - date2)) In MySQL one can use: datediff(date1,date2) * 86400 In Access one can use: DateDiff("s",date1,date2) etc... None of the above pleases me - I'ld like a common expression for all these databases. |
#4
| |||
| |||
|
|
You could use the datetime type. The difference between two datetime values is in seconds, as in: datetime1-datetime2 |
|
This could turn into the DBMS equivalent of programming "100 Bottles of Beer" in various programming languages. |
|
Time to understand that even if these products all are called DBMSes it doesn't mean all are the same or even similar. |
#5
| |||
| |||
|
|
On 11 mei, 18:39, Gene Wirchenko <g... (AT) ocis (DOT) net> wrote: You could use the datetime type. The difference between two datetime values is in seconds, as in: datetime1-datetime2 This subtraction returns a value of type 'interval'. Getting the duration of an interval in seconds isn't standard either |
|
On 11 mei, 16:42, Gints Plivna <gints.pli... (AT) gmail (DOT) com> wrote: Time to understand that even if these products all are called DBMSes it doesn't mean all are the same or even similar. Understood... and confirms my suspicion - no general solution possible even for something as simple, common and basic as subtracting 2 dates... |
|
The level of standardisation in SQL is below what I expected. :-( An variation on the comment from Gints: Time for the DBMS vendors to understand that their lack of standardisation is costing people a lot of time and effort. |
#6
| |||
| |||
|
|
Understood... and confirms my suspicion - no general solution possible even for something as simple, common and basic as subtracting 2 dates... The level of standardisation in SQL is below what I expected. :-( |

|
An variation on the comment from Gints: Time for the DBMS vendors to understand that their lack of standardisation is costing people a lot of time and effort. |

#7
| |||
| |||
|
|
The level of standardisation in SQL is below what I expected. :-( The problem actually is much bigger - there are many architectural differences among various DB and these are much more important than just some syntactic problems. If you don't care about them then either 1) you are creating application that won't work correctly on at least some of your DB's 2) you are using the very very basic features of each DB and so your customers will waste much $$ gathering licences for thousands of bucks and using only 1% of features they bought |
|
An variation on the comment from Gints: Time for the DBMS vendors to understand that their lack of standardisation is costing people a lot of time and effort. There are many cars around an you cannot simply get engine from Ferrari and put it into Trabant. Each model is predicted for different needs and resources, each is manufactured by different company, developed by different people thinking differently, each have his own history, they'll never be equal. And that's why we have alternatives, that's why the life is interesting ![]() |
#8
| |||
| |||
|
|
Gints Plivna wrote: The level of standardisation in SQL is below what I expected. :-( The problem actually is much bigger - there are many architectural differences among various DB and these are much more important than just some syntactic problems. If you don't care about them then either 1) you are creating application that won't work correctly on at least some of your DB's 2) you are using the very very basic features of each DB and so your customers will waste much $$ gathering licences for thousands of bucks and using only 1% of features they bought Agree. There are many architectural differences. Most only affect DBAs and are of less concern. More important is the effect on application software. Here syntactic/semantic differences are pretty important. The only major one outside of that is tuning SQL commands, and that one is pretty major. |
#9
| |||
| |||
|
|
Gints Plivna wrote: The level of standardisation in SQL is below what I expected. :-( The problem actually is much bigger - there are many architectural differences among various DB and these are much more important than just some syntactic problems. If you don't care about them then either 1) you are creating application that won't work correctly on at least some of your DB's 2) you are using the very very basic features of each DB and so your customers will waste much $$ gathering licences for thousands of bucks and using only 1% of features they bought Agree. There are many architectural differences. Most only affect DBAs and are of less concern. More important is the effect on application software. Here syntactic/semantic differences are pretty important. The only major one outside of that is tuning SQL commands, and that one is pretty major. An variation on the comment from Gints: Time for the DBMS vendors to understand that their lack of standardisation is costing people a lot of time and effort. There are many cars around an you cannot simply get engine from Ferrari and put it into Trabant. Each model is predicted for different needs and resources, each is manufactured by different company, developed by different people thinking differently, each have his own history, they'll never be equal. And that's why we have alternatives, that's why the life is interesting ![]() Disagree. A better analogy might be switching cars rather than engines. Here the user experience is easier --- you can probably jump in most cars and start driving right away. Unfortunately, humans are much more flexible than software ;^) |
|
Also for DBMSs, a standard (ANSI SQL) exists ... that is willfully ignored by vendors. In addition, there is the Relational Model (RM), mostly ignored by vendors too. It's RM where tuning is a problem. Improper, arcane optimization severely impacts relational power. |
#10
| |||
| |||
|
|
On May 15, 7:01 pm, Lee Fesperman <first... (AT) ix (DOT) netcom.com> wrote: |
|
Disagree. A better analogy might be switching cars rather than engines. Here the user experience is easier --- you can probably jump in most cars and start driving right away. Unfortunately, humans are much more flexible than software ;^) Yes, the analogy is better but the same issues exist. Ever get a rental car where the Lights switch was in a different place? Wipers? Two basic safety features are not standard on cars. |
![]() |
| Thread Tools | |
| Display Modes | |
| |