Re: To go from a datetime to an integer number of seconds...
Posted in 1996
Paul Roberts wrote: > > Is there a function available in I-SQL or I-4GL which will convert > a datetime into an integer, that integer being the number of seconds > between the datetime and some specific instant? > > i.e., in the same way that: > > select date_stamp - '1/1/1900' > from some_table > > will get me "how many days have passed since 1/1/1900?", how do I find > out how many seconds have passed since some arbitrary "beginning of time"? > > There's probably some painfully obvious answer to this, but datetime > arithmetic always confuses me, and it is a Monday morning (almost)... > > - Paul selection into an interval is easy: select datetime_stamp - extend("1900-01-01 00:00:00", YEAR TO SECOND) from some_table in 4GL you can then put the interval into a char, and the char into an integer: DEFINE interval_variable INTERVAL HOUR(9) TO HOUR DEFINE char_variable CHAR(10) DEFINE integer_variable INTEGER FOREACH ... INTO interval_variable LET char_variable = interval_variable LET integer_variable = char_variable ... END FOREACH I tested a variation of this; there may be some scale details to work out. I suspect there might be a more clever SQL solution involving temp tables and the like. -- //////////////// ======================================================= ////////// // Dennis J. Pimple Informix Software, Inc. ////// / /// Principal Consultant 5299 DTC Blvd Suite 740 ///// // //// dennisp@informix.com Englewood CO 80111 //// // ///// /// // ////// recept: 303-850-0210 // // /////// direct: 303-740-5611 Opinions expressed are mine, / /////////// fax: 303-843-6408 and do not necessarily //////////////// http://www.informix.com reflect those of my employer