Re: Portable SQL to compute a date difference in seconds???
- From: Gene Wirchenko <genew@xxxxxxxx>
- Date: Fri, 11 May 2007 09:39:47 -0700
johan.de.taeye@xxxxxxxxx wrote:
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.
Dates are implemented differently in different DBMSs.
In Visual FoxPro, the difference between two dates is
date1-date2
For seconds, you could multiply by 86400 although this gives
nonsensical results as your data is not that precise.
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.
Sincerely,
Gene Wirchenko
Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.
.
- Follow-Ups:
- Re: Portable SQL to compute a date difference in seconds???
- From: johan . de . taeye
- Re: Portable SQL to compute a date difference in seconds???
- References:
- Portable SQL to compute a date difference in seconds???
- From: johan . de . taeye
- Portable SQL to compute a date difference in seconds???
- Prev by Date: Re: Portable SQL to compute a date difference in seconds???
- Next by Date: Re: Free database chart program
- Previous by thread: Re: Portable SQL to compute a date difference in seconds???
- Next by thread: Re: Portable SQL to compute a date difference in seconds???
- Index(es):