vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Sorry, This should be simple, but brain is hurting... How do I convert a Current Time to a Decimal 6,0 (HMS)? There must be a cleaner way then this: Insert into Table Values Dec( Substr(Char(CURRENT TIMESTAMP),12,2) || Substr(Char(CURRENT TIMESTAMP),15,2) || Substr(Char(CURRENT TIMESTAMP),18,2) ,6,0) TIA, Chris |
| |||
| Take a peak at HOUR(), MINUTE(), and SECOND(). DEC() can also be used directly on the timestamp. integer(dec(current timestamp) - dec(current date) * 1000000) or round(dec(current timestamp) - dec(current date) * 1000000, 0) |
| |||
| Simply use DECIMAL function. ------------------------- Commands Entered ------------------------- VALUES (Current Time, DECIMAL(Current Time)); -------------------------------------------------------------------- 1 2 -------- -------- 23:08:27 230827. 1 record(s) selected. |
| |||
| Looking in your example, you want to convert from Current Timestamp (NOT from Current Time). So, first convert to Time from Current Timestamp, then apply DEC function. ------------------------- Commands Entered ------------------------- VALUES (Current Timestamp, DECIMAL(TIME(Current Timestamp))); -------------------------------------------------------------------- 1 2 -------------------------- -------- 2005-08-19-23.14.15.089000 231415. 1 record(s) selected. |
| |||
| Gosh I wish that worked. I should note, I'm on an iSeries DB2 UDB (V5R3). Trying: Insert into TABLE values(DECIMAL(Current Time)) or Insert into TABLE values(DECIMAL(Current Time), 6,0) gives me. An operand has been specified for the arithmetic function or operator DECIMAL that is not valid. -- User-defined types cannot be specified as operands of operators or scalar functions. User-defined types can only be specified with operators and within user-defined functions created specifically for that type. -- The operand of DIGITS can be any numeric or numeric compatible type except floating-point. -- The operand of INTEGER, SMALLINT, BIGINT, FLOAT, DOUBLE, and DOUBLE_PRECISION cannot be date, time, or timestamp. -- The other functions or operators require numeric or numeric compatible operands. Recovery . . . : Ensure all operands of function or operator DECIMAL are valid. Correct the operands. Try the request again. |