473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Convert Current Time to Dec

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

Nov 12 '05 #1
8 18656
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)

Nov 12 '05 #2
Simply use DECIMAL function.

------------------------- Commands Entered -------------------------
VALUES (Current Time, DECIMAL(Current Time));
--------------------------------------------------------------------

1 2
-------- --------
23:08:27 230827.

1 record(s) selected.

Nov 12 '05 #3
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.

Nov 12 '05 #4
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.

Nov 12 '05 #5
Looked at Hour/Min/Sec, so is this the cleanest why?

SELECT Dec(Hour(Now()) || Minute(Now()) || Second(Now()))
FROM SYSIBM/SYSDUMMY1

Chris

Nov 12 '05 #6
If it is the cleanest, i don't know, i was just offering an alternative.

Nov 12 '05 #7
I have no iSeries test environment. So, following example was only
checked by iSeries manual DB2 UDB SQL Reference(V5R2).
(This works on DB2 UDB for LUW).

SELECT Current Timestamp
, TIME(Current Timestamp) - '00:00:00'
FROM SYSIBM.SYSDUMMY1

Nov 12 '05 #8
Cool, that works. Tx

Nov 12 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: MarthaR | last post by:
I am trying to add the current time to a field when the user clicks on the toggle button next to the field. I am getting a time of 12:00:00 AM each time I click the button. How do I get a...
18
by: Tim Quon | last post by:
Hi I need to print the current time. I found an example where this is done as followed: long *mytime; time(mytime); printf("time: %s", ascitime(mytime); But this doesn't work and prints...
3
by: | last post by:
I have a datetime field in table. I want to insert the current time of database server to the table thr ASP.NET (C#). I have dataset to do the insert: DataSet1.TableNameRow rowNew =...
5
by: ECVerify.com | last post by:
I am trying to convert a computers local time to Pacific time, I can get it back to UTC pretty easy but I actually want to convert whatever the local time is on the computer I want to calculate...
4
by: Gary Wessle | last post by:
Hi I am not getting current time with this program, what am I doing wrong? #include <ctime> #include <iostream> using namespace std; #define P(x) cout << #x " = " << (x) << "\n";
3
by: Mark Ingram | last post by:
Hi, I'd like to know the best way of checking the current time during a demonstration product. At the minute i store the first run date, then compare that to the system time, but obviously a user...
2
by: Mark Poppers | last post by:
I would like to get the current time(stamp) (including the milliseconds) and assign it into a string variable with a format like: xxxx mytime = getcurrentsystemtime(); string mytime =...
8
by: rhepsi | last post by:
Hii all, im doin a vb project where i need to update the current date..?? (vb) Private Function updateDate(ByVal strDate As String) As String 'to convert valid date format ...
1
by: star111792 | last post by:
hi, can anyone plz tell me that which built-in classes of java are used to get current time? what are the methods used? how 2 times can be compared to get the mean time? also i want to ask...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.