473,399 Members | 2,159 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,399 software developers and data experts.

Converting from unix timestamp format into db2 timestamp format

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
is the number of seconds since 1/1/1970 which I need to convert into a
db/2 timestamp format.

I've found a UDF called unixtimestamp which accepts a big intetger and
returns a db/2 timestamp but I'm not sure how to incorporate it into a
prepare statement.

The following is an excerpt from the perl file which executes the
prepare statement.

$sth=$dbh->prepare("INSERT INTO
squid.logger(cacheip,msec,elapsed,bill,code,\
status,bytes,url,userident,host)\
VALUES(?,?,?,?,?,?,?,?,?,?)");
msec is defined as being of data type timestamp.
A perl variable called $cts is a string representation of the web
cache log field in milliseconds.

How would I modify the above prepare statement to incorporate the UDF

would it be ?
"insert into squid.logger(cacheip,unixtimestamp(bigint($cts)),. .....

TIA
Alex
Nov 12 '05 #1
2 16196
Alex <A.******@hull.ac.uk> wrote:
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.
It's named "DB2"
The problem I've got is that the log files have a timestamp field that
is the number of seconds since 1/1/1970 which I need to convert into a
db/2 timestamp format.

I've found a UDF called unixtimestamp which accepts a big intetger and
returns a db/2 timestamp but I'm not sure how to incorporate it into a
prepare statement.
The following is an excerpt from the perl file which executes the
prepare statement.

$sth=$dbh->prepare("INSERT INTO
squid.logger(cacheip,msec,elapsed,bill,code,\
status,bytes,url,userident,host)\
VALUES(?,?,?,?,?,?,?,?,?,?)");

msec is defined as being of data type timestamp.
A perl variable called $cts is a string representation of the web
cache log field in milliseconds.

How would I modify the above prepare statement to incorporate the UDF

would it be ?
"insert into squid.logger(cacheip,unixtimestamp(bigint($cts)),. .....


No. After the name of the table you want to insert into follow the column
names. But you want to change the (data types of the) values that are to
be inserted. So you do this:

INSERT
INTO squid.logger(cacheip, msec, elapsed, bill, code,
status, bytes, url, userident, host)
VALUES (?, UnixTimestamp(CAST(? AS BIGINT)), ?, ?, ?, ?, ?, ?, ?, ?)

Note that you need the CAST to BIGINT here (instead of the function call) so
that DB2 can correctly resolve and find the function UNIXTIMESTAMP.
Without the cast, DB2 does not know anything about the data type for the
parameter marker '?' and would not know which function is to be called.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2
Ian
Alex wrote:
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
is the number of seconds since 1/1/1970 which I need to convert into a
db/2 timestamp format.


You might also consider doing this in perl, it's pretty simple and may
be a little faster (i.e. you avoid the overhead of calling the UDF for
each row).

@t = localtime($unix_ts);
$db2_ts = sprintf("%4d-%2d-%2d-%2d.%2d.%2d.000000",
$t[5]+1900, $t[4]+1, $t[3], $t[2], $t[1], $t[0]);
Good luck,
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 12 '05 #3

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

Similar topics

6
by: Kit | last post by:
Howdy! I have some dates in a MySQL database that are in a 'Y-m-d' format. Is there a way to have PHP read these dates and convert them to a 'd-M-Y' format?
13
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
3
by: Yariv via SQLMonster.com | last post by:
Hi, When I open a tabe in the SQL enterprise manager I see the Timestamp Field in this Format : 24/01/2005 16:45:00 However when I'm using the Query analyzer or other SQL Client I see the...
15
by: Daniel Schuchardt | last post by:
Hi @ all, i'm sure there was a psql-function to transfere my Blob-Data to the server but I can't remember. I have a script like this : UPDATE xy SET z = lo_import('localpath_and_file'); ...
3
by: Tgone | last post by:
Hello, I need to convert a MySQL date "2007-03-08", into "March 8th, 2007". Normally I would use MySQL to accomplish this task but I have to use PHP. Here's my code: echo date("F jS, Y",...
2
by: shenanwei | last post by:
DB2 V8.2 on AIX, type II index is created. I see this from deadlock event monitor. 5) Deadlocked Connection ... Participant no.: 2 Lock wait start time: 09/18/2006 23:04:09.911774 .........
12
by: Vincent Delporte | last post by:
Hello My site is hosted on a server in the US, hence set up to use the mm/dd/yyyy date format instead of the European dd/mm/yyyy. Also, MySQL stores dates as yyyy-mm-dd, so I need to convert...
6
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!
4
by: skulkrinbait | last post by:
Hello How can I convert a date into the Unix timestamp? I don't really mind what format the date is in, something like MMDDYY would be fine, can someone show me what code I would need to do...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...
0
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...

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.