How many fractions between two datetime variable?
Posted in 2009
Topics: General Discussion
Hi, Do anybody know how to calculate how man fractions between two datatime variable ? thanks.
select (dtcol1 - dtcol2) :: INTERVAL FRACTION(5) TO FRACTION .... ; Art Art S. Kagel Oninit (www.oninit.com) IIUG Board of Directors (art@iiug.org) Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Oninit, the IIUG, nor any other organization with which I am associated either explicitly or implicitly. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Thu, Aug 6, 2009 at 4:59 AM, CHUAN LU <luchuan114@sina.com> wrote: > Hi, > > Do anybody know how to calculate how man fractions between two datatime > variable ? thanks. > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --001636c5c2f17d0a960470ccf5ae
On Thu, Aug 6, 2009 at 02:59, CHUAN LU<luchuan114@sina.com> wrote: > Do anybody know how to calculate how man fractions between two datatime > variable ? thanks. Ancient history - but... Art Kagel suggested (working from memory): SELECT (datetime2 - datetime1)::INTERVAL FRACTION TO FRACTION(5) AS delta, ... I'd recommend replacing the earlier FRACTION with SECOND(9). That will allow you around 30 years' worth of difference between the two dates and still give you the answer in seconds and fractions of a second, whereas the original answer only allows the difference to be less than 1 second. Also, if you want the value as a number instead of as an interval, then you have to do two more casts: SELECT (datetime2 - datetime1)::INTERVAL SECOND(9) TO FRACTION::CHAR(16)::DECIMAL(16) AS delta, ... -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2008.0513 -- http://dbi.perl.org/ "Blessed are we who can laugh at ourselves, for we shall never cease to be amused." NB: Please do not use this email for correspondence. I don't necessarily read it every week, even. Mike Ditka - "If God had wanted man to play soccer, he wouldn't have given us arms." - http://www.brainyquote.com/quotes/authors/m/mike_ditka.html