473,800 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting from time in seconds to timestamp format

hi,

I'm moving a mysql database over to using db2 V9.5

The database is used by our radius server to store network accounting
information from our switches.
One parameter is the length of a network session in seconds.

In mysql there is a sec_to_time function which i then used to store
the session time as a char string
I want to do something similar in db2 and thought that the best way
would be to store it in a timestamp column.

Can i do that?

any better way of storing the time?

TIA
alex
Jun 27 '08 #1
6 6595
alexs wrote:
hi,

I'm moving a mysql database over to using db2 V9.5

The database is used by our radius server to store network accounting
information from our switches.
One parameter is the length of a network session in seconds.

In mysql there is a sec_to_time function which i then used to store
the session time as a char string
I want to do something similar in db2 and thought that the best way
would be to store it in a timestamp column.

Can i do that?

any better way of storing the time?
Store time as TIME?
When you refer to "seconds" do you mean:
* Seconds since midnight,
* seconds since 1972
* seconds since....

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #2
On Apr 17, 1:54 pm, alexs <A.Sha...@hull. ac.ukwrote:
In mysql there is a sec_to_time function which i then used to store
the session time as a char string
You mean you are currently doing something like this?

mysqlCREATE TABLE network_time (
- seconds int(11) default NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.01 sec)

mysqlINSERT INTO network_time VALUES (3600),(5400),( 7200),(43200),
(86400);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysqlSELECT sec_to_time(sec onds) AS elapsed FROM network_time;
+----------+
| elapsed |
+----------+
| 01:00:00 |
| 01:30:00 |
| 02:00:00 |
| 12:00:00 |
| 24:00:00 |
+----------+
5 rows in set (0.00 sec)

--
Serman D.
Jun 27 '08 #3
On Apr 17, 1:54 pm, alexs <A.Sha...@hull. ac.ukwrote:
In mysql there is a sec_to_time function which i then used to store
the session time as a char string
Are you doing something like below? I guess you can continue to store
elapsed seconds as an integer and create a function yourself to do the
conversion to 'hh:mm:ss' (unless it already exists in DB2).

mysqlCREATE TABLE `network_time` ( `col1` int(11) default NULL )
ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.01 sec)

mysqlINSERT INTO network_time VALUES (3600),(5400),( 7200),(43200),
(86400);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysqlSELECT sec_to_time(col 1) AS elapsed FROM network_time;
+----------+
| elapsed |
+----------+
| 01:00:00 |
| 01:30:00 |
| 02:00:00 |
| 12:00:00 |
| 24:00:00 |
+----------+
5 rows in set (0.01 sec)

--
Serman D.
Jun 27 '08 #4
Serman D. wrote:
On Apr 17, 1:54 pm, alexs <A.Sha...@hull. ac.ukwrote:
>In mysql there is a sec_to_time function which i then used to store
the session time as a char string

Are you doing something like below? I guess you can continue to store
elapsed seconds as an integer and create a function yourself to do the
conversion to 'hh:mm:ss' (unless it already exists in DB2).

mysqlCREATE TABLE `network_time` ( `col1` int(11) default NULL )
ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.01 sec)

mysqlINSERT INTO network_time VALUES (3600),(5400),( 7200),(43200),
(86400);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysqlSELECT sec_to_time(col 1) AS elapsed FROM network_time;
+----------+
| elapsed |
+----------+
| 01:00:00 |
| 01:30:00 |
| 02:00:00 |
| 12:00:00 |
| 24:00:00 |
+----------+
5 rows in set (0.01 sec)
OK, DB2 has a midnight_second s() fucntion to tuen time into seconds but
not the inverse.
But.. That's easily fixed:
CREATE FUNCTION SEC_TO_TIME(arg INTEGER) RETURNS TIME CONTAINS SQL
NO EXTERNAL ACTION DETERMINISTIC
RETURN TIME('00:00:00' )
+ (arg / 3600) HOURS
+ MOD(arg / 60, 60) MINUTES
+ MOD(arg, 3600) SECONDS;

Note that this is NOT an INTERVAL. So 24 hours is as far as it can hold.
You could return astring such as:
RETURNS VARCHAR(12)...
RETURN TRIM(CHAR(arg / 3600)) || ':'
|| TRIM(CHAR(MOD(a rg / 60, 60)) || ':'
|| TRIM(MOD(arg, 3600));

That's plenty of hours..

(All untested)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #5
On Apr 18, 12:42*pm, Serge Rielau <srie...@ca.ibm .comwrote:
Serman D. wrote:
On Apr 17, 1:54 pm, alexs <A.Sha...@hull. ac.ukwrote:
In mysql there is a sec_to_time function which i then used to store
the session time as a char string
Are you doing something like below? I guess you can continue to store
elapsed seconds as an integer and create a function yourself to do the
conversion to 'hh:mm:ss' (unless it already exists in DB2).
mysqlCREATE TABLE `network_time` ( * `col1` int(11) default NULL )
ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.01 sec)
mysqlINSERT INTO network_time VALUES (3600),(5400),( 7200),(43200),
(86400);
Query OK, 5 rows affected (0.00 sec)
Records: 5 *Duplicates: 0 *Warnings: 0
mysqlSELECT sec_to_time(col 1) AS elapsed FROM network_time;
+----------+
| elapsed *|
+----------+
| 01:00:00 |
| 01:30:00 |
| 02:00:00 |
| 12:00:00 |
| 24:00:00 |
+----------+
5 rows in set (0.01 sec)

OK, DB2 has a midnight_second s() fucntion to tuen time into seconds but
not the inverse.
But.. That's easily fixed:
CREATE FUNCTION SEC_TO_TIME(arg INTEGER) RETURNS TIME CONTAINS SQL
NO EXTERNAL ACTION DETERMINISTIC
RETURN TIME('00:00:00' )
* * * + (arg / 3600) HOURS
* * * + MOD(arg / 60, 60) MINUTES
* * * + MOD(arg, 3600) SECONDS;

Note that this is NOT an INTERVAL. So 24 hours is as far as it can hold.
You could return astring such as:
RETURNS VARCHAR(12)...
RETURN TRIM(CHAR(arg / 3600)) || ':'
* * *|| TRIM(CHAR(MOD(a rg / 60, 60)) || ':'
* * *|| TRIM(MOD(arg, 3600));

That's plenty of hours..

(All untested)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
sorry didn't make myself clear. The variable is a radius server
accounting attribute and is an elapsed time i.e. the number of seconds
since the radius server sent a start of session accounting packet.
Some of our students log onto the network and never log off so we can
see elapsed times of days weeks .....

Many thanks for the above
Alex
Jun 27 '08 #6
alexs wrote:
On Apr 18, 12:42 pm, Serge Rielau <srie...@ca.ibm .comwrote:
>Serman D. wrote:
>>On Apr 17, 1:54 pm, alexs <A.Sha...@hull. ac.ukwrote:
In mysql there is a sec_to_time function which i then used to store
the session time as a char string
Are you doing something like below? I guess you can continue to store
elapsed seconds as an integer and create a function yourself to do the
conversion to 'hh:mm:ss' (unless it already exists in DB2).
mysqlCREATE TABLE `network_time` ( `col1` int(11) default NULL )
ENGINE=MyIS AM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.01 sec)
mysqlINSERT INTO network_time VALUES (3600),(5400),( 7200),(43200),
(86400);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysqlSELECT sec_to_time(col 1) AS elapsed FROM network_time;
+----------+
| elapsed |
+----------+
| 01:00:00 |
| 01:30:00 |
| 02:00:00 |
| 12:00:00 |
| 24:00:00 |
+----------+
5 rows in set (0.01 sec)
OK, DB2 has a midnight_second s() fucntion to tuen time into seconds but
not the inverse.
But.. That's easily fixed:
CREATE FUNCTION SEC_TO_TIME(arg INTEGER) RETURNS TIME CONTAINS SQL
NO EXTERNAL ACTION DETERMINISTIC
RETURN TIME('00:00:00' )
+ (arg / 3600) HOURS
+ MOD(arg / 60, 60) MINUTES
+ MOD(arg, 3600) SECONDS;

Note that this is NOT an INTERVAL. So 24 hours is as far as it can hold.
You could return astring such as:
RETURNS VARCHAR(12)...
RETURN TRIM(CHAR(arg / 3600)) || ':'
|| TRIM(CHAR(MOD(a rg / 60, 60)) || ':'
|| TRIM(MOD(arg, 3600));

That's plenty of hours..

(All untested)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

sorry didn't make myself clear. The variable is a radius server
accounting attribute and is an elapsed time i.e. the number of seconds
since the radius server sent a start of session accounting packet.
Some of our students log onto the network and never log off so we can
see elapsed times of days weeks .....

Many thanks for the above
Alex
OK, then that second function should do the job. Trivial to extend to
show days/weeks as a unit as well.
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #7

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

Similar topics

2
16224
by: Alex | last post by:
Hi all, Got a small problem here. I have a number of web caches here that generate loads and loads of log files and instead of keeping them for analysis I want to write them to a db/2 database. The problem I've got is that the log files have a timestamp field that
0
4121
by: jjs0713 | last post by:
Hi, Everyone ! I made a C program. I want to know serial communication at micom which is ATMEL 89C52. It's received to micom RX pin(serial comm.) NMEA format from some set. I'd like to take UTC Time. then I'll display to LCD output. I really need to help which is to get UTC time from NMEA format. 1. NMEA format $GPGGA,000915.5,3727.85245,N,12702.53467,E,0,00,,684.6,M,18.5,M,,*71
0
2170
kiss07
by: kiss07 | last post by:
Hi friends, I have one doubt , whts difference between Time and Timestamp data type in Oracle 9i. Thanks, Kiss07.
2
6501
kiss07
by: kiss07 | last post by:
Hi, Any body Send reply.. What is difference between datatype Time and TimeStamp? Regards, Kiss07
6
34102
by: marc | last post by:
hi im trying to convert Date() into a unix timestamp so i can stick the result into a mysql db, please help!
67
4819
by: James Harris | last post by:
I have a requirement to store timestamps in a database. Simple enough you might think but finding a suitably general format is not easy. The specifics are 1) subsecond resolution - milliseconds or, preferably, more detailed 2) not bounded by Unix timestamp 2038 limit 3) readable in Java 4) writable portably in Perl which seems to mean that 64-bit values are out 5) readable and writable in Python
5
6058
Plater
by: Plater | last post by:
So I have been working with the SNTP protocol (RFC4330) And it is saying that the timestamp format of 64bits is: . 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Seconds | ...
1
5564
by: mohini2000 | last post by:
Hi I want to convert timestamp forrmat to date. For eg: Suppose I give timestamp format on Console as MM/DD/YYHH:mm:ss. Output should be: 08/24/0714:34:32 If I give MM/DD/YYTHHmmss Output should be: 08/24/07T143432
1
1361
by: chopoff | last post by:
Hey, I have lots of times in the following format: g.i, so 12.30, 1.05, 2.25, 4.50 etc. However I would like to convert the time into a timestamp, so I can sort them by earliest to latest, as at the moment I don't think I can do that? Help appreciated! Thanks
4
32961
by: ahmurad | last post by:
Dear Brothers, I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used the MYSQL Tables DateTime Type as Text. Time-formet 1. 04:02:27 16/01/2009 Time-formet 2. 16/01/2009 13:53:19 Time-formet 3. 00901E+13 Time-formet 4. Wed Jan 14 00:09:09 BDT 2009
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
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 we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.