473,509 Members | 3,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Number to Time Conversion

is it possible in sql to convert a 6 digit integer in to a time field
with out converting to character and then substringing
e.g
161201 to 16:12:01

Nov 12 '05 #1
3 21505
SELECT TIME('00:00:00') + CAST(int6 AS DEC(6,0)) "Time"
FROM (VALUES 161201) Q(int6);
------------------------------------------------------------------------------

Time
--------
16:12:01

1 record(s) selected.

OR

SELECT TIME('00:00:00')
+ (int6/10000) Hours
+ MOD(int6/100, 100) Minutes
+ MOD(int6, 100) Seconds AS "TIME"
FROM (VALUES 161201) Q(int6);
------------------------------------------------------------------------------

TIME
--------
16:12:01

1 record(s) selected.

Nov 12 '05 #2
Tonkuma wrote:
SELECT TIME('00:00:00') + CAST(int6 AS DEC(6,0)) "Time"
FROM (VALUES 161201) Q(int6);
------------------------------------------------------------------------------

Time
--------
16:12:01

1 record(s) selected.

OR

SELECT TIME('00:00:00')
+ (int6/10000) Hours
+ MOD(int6/100, 100) Minutes
+ MOD(int6, 100) Seconds AS "TIME"
FROM (VALUES 161201) Q(int6);
------------------------------------------------------------------------------

TIME
--------
16:12:01

1 record(s) selected.

... or encapsulated:
CREATE FUNCTION TIME(int6 INT)
RETURNS TIME
CONTAINS SQL NO EXTERNAL ACTION DETERMINISTIC
RETURN
TIME('00:00:00')
+ (int6/10000) Hours
+ MOD(int6/100, 100) Minutes
+ MOD(int6, 100) Seconds

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3
cheers !

Nov 12 '05 #4

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

Similar topics

6
8261
by: John Bentley | last post by:
John Bentley writes at this level: If we think about our savings accounts then division never comes in (as far as I can see). We deposit and withdraw exact amounts most of the time. Occasionaly...
4
5818
by: oddstray | last post by:
Hi, I have a number which is larger than the max unsigned long int. I don't have 64-bit integers available to me. I need to get the resulting 40-bit hex string. I can't find any algorithm...
17
3998
by: jake1138 | last post by:
Here is a function I have to get a number at the end of a string. I'm posting this in case it proves helpful to someone. Comments are welcome. int getnum(char *str) { char buffer; char *buf...
3
1896
by: Chandu | last post by:
Hi, I am working on awk programming which is similar to C programming and have got a doubt about time function returning a float value. Ex: 01:01:30 should return 61.5 when i have tried my way i...
11
13394
by: Leroy | last post by:
Hello, I have a question regarding the maximum number of parameters that can be passed to a procedure. In VB 6 the max was 60. What is the max for Dot Net? please and thanks.
5
2290
by: Pavils Jurjans | last post by:
Hello, I am somewhat lost in the implicit/expicit possible/impossible type casting in C#... I need to write a class, which among other things, must have wat to read a numeric value type, and...
4
118780
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
14
16200
by: dharmdeep | last post by:
Hi friends, I need a sample code in C which will convert a Hexadecimal number into decimal number. I had written a code for that but it was too long, I need a small code, so request u all to...
5
13632
by: Beemer Biker | last post by:
I cant seem to get that date into any DateTime to make my calculation directly by subtracting "01-01-0000" from "now". After reading this:...
23
9746
by: neha_chhatre | last post by:
which is the best format specifier(data type) if i have to work with decimal number. also please tell me the syntax for truncating a decimal number please reply as soon as possible
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.