473,399 Members | 3,302 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 timestamp to int?


Folks,

How can I convert date/time/timestamp to an integer?

According to UDB 8.1 docs that I have,
INTEGER('1964-07-20') should return 19640720, but when I run the SQL
statement I get different answer:

# db2 "VALUES INTEGER(CHAR(1964-07-20))"

1
-----------
1937

1 record(s) selected.

How can I convert CURRENT TIMESTAMP to a integer?

# db2 "VALUES INTEGER(CHAR(CURRENT TIMESTAMP))"

1
-----------
SQL0420N Invalid character found in a character string argument of the
function "INTEGER". SQLSTATE=22018


--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: No************@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
Dec 12 '07 #1
5 32816
On Dec 12, 10:19 am, Hemant Shah <s...@typhoon.xnet.comwrote:
Folks,

How can I convert date/time/timestamp to an integer?

According to UDB 8.1 docs that I have,
INTEGER('1964-07-20') should return 19640720, but when I run the SQL
statement I get different answer:

# db2 "VALUES INTEGER(CHAR(1964-07-20))"

1
-----------
1937

1 record(s) selected.

How can I convert CURRENT TIMESTAMP to a integer?

# db2 "VALUES INTEGER(CHAR(CURRENT TIMESTAMP))"

1
-----------
SQL0420N Invalid character found in a character string argument of the
function "INTEGER". SQLSTATE=22018

--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: NoJunkMails...@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
There is a function called DAYS(expression) that does something
similar to what you want.

DAYS scalar function
>>-DAYS--(--expression--)--------------------------------------><

The schema is SYSIBM.

The DAYS function returns an integer representation of a date.

The argument must be a date, timestamp, or a valid character string
representation of a date or timestamp that is neither a CLOB nor a
LONG VARCHAR. In a Unicode database, if a supplied argument is a
graphic string, it is first converted to a character string before the
function is executed.

The result of the function is a large integer. If the argument can be
null, the result can be null; if the argument is null, the result is
the null value.

The result is 1 more than the number of days from January 1, 0001 to
D, where D is the date that would occur if the DATE function were
applied to the argument.
Dec 12 '07 #2
Ian
Hemant Shah wrote:
Folks,

How can I convert date/time/timestamp to an integer?

According to UDB 8.1 docs that I have,
INTEGER('1964-07-20') should return 19640720, but when I run the SQL
statement I get different answer:

# db2 "VALUES INTEGER(CHAR(1964-07-20))"

1
-----------
1937

1 record(s) selected.
This doesn't work as you typed it.

values integer(current date) returns:

== 20071212

values integer(date('1964-07-20')) returns:

== 19640720

How can I convert CURRENT TIMESTAMP to a integer?

# db2 "VALUES INTEGER(CHAR(CURRENT TIMESTAMP))"

1
-----------
SQL0420N Invalid character found in a character string argument of the
function "INTEGER". SQLSTATE=22018

Use the BIGINT() function:

values bigint(current timestamp)

== 20071212085812

Dec 12 '07 #3
While stranded on information super highway Ian wrote:
Hemant Shah wrote:
>Folks,

How can I convert date/time/timestamp to an integer?

According to UDB 8.1 docs that I have,
INTEGER('1964-07-20') should return 19640720, but when I run the SQL
statement I get different answer:

# db2 "VALUES INTEGER(CHAR(1964-07-20))"

1
-----------
1937

1 record(s) selected.

This doesn't work as you typed it.

values integer(current date) returns:

== 20071212

values integer(date('1964-07-20')) returns:

== 19640720

>How can I convert CURRENT TIMESTAMP to a integer?

# db2 "VALUES INTEGER(CHAR(CURRENT TIMESTAMP))"

1
-----------
SQL0420N Invalid character found in a character string argument of the
function "INTEGER". SQLSTATE=22018


Use the BIGINT() function:

values bigint(current timestamp)

== 20071212085812
I tried bigint, but it does not work:

# db2 "values BIGINT(CURRENT TIMESTAMP)"
SQL0440N No function by the name "BIGINT" having compatible arguments was
found in the function path. SQLSTATE=42884
I am running DB2 v7.1.0.77 on Linux.

--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: No************@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
Dec 12 '07 #4
Hemant Shah wrote:
I am running DB2 v7.1.0.77 on Linux.
What one finds in the basement, eh?
http://www.cbc.ca/arts/artdesign/sto...galleries.html

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Dec 12 '07 #5
On Dec 13, 5:42 am, Hemant Shah wrote:
I tried bigint, but it does not work:

# db2 "values BIGINT(CURRENT TIMESTAMP)"
SQL0440N No function by the name "BIGINT" having compatible arguments was
found in the function path. SQLSTATE=42884

I am running DB2 v7.1.0.77 on Linux.
INTEGER(date | time) and BIGINT(date | time | timestamp) are supported
on DB2 V8 or later. DB2 V7 doesn't support those arguments.
Although it will be better to upgrade DB2 as Serge suggested, another
temporary solution may be to create UDF(s).
Dec 13 '07 #6

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

Similar topics

2
by: Frank | last post by:
I am timing employees who take a test. I have the start time and end time, which are unix epochs, and subtracing the start from the end will give me a large number of seconds, for example 552. I...
1
by: David Greenberg | last post by:
Hi I'm interested in using the timestamp data type & I have some questions. As far as I can understand the contant of a timestamp column is a binary value. Is there any connection between that...
0
by: Eugene | last post by:
Hi, I have been battling with this for days now. If you execute the SQL below you will get the following result: 0x3078303030303030, which is incorrect. It looks like the conversion is more...
2
by: Russell Smith | last post by:
Timestamps support infinity. However if appears dates do not. When timestamps are cast to dates, there is no output. Is this an acceptable option or not? Below are a number of examples...
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 .........
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!
2
by: Yash3 | last post by:
Hey I am trying this create or replace FUNCTION DatesPast ( v_dueDate Timestamp ) RETURN NUMBER AS DaysPast DATE BEGIN
3
by: wongjoekmeu | last post by:
Hello all, I have a C++ program ( I am not sure if this is the right place to post this question ), One of the function returns two unsigned integers which are referred to be TimestampLo and...
11
by: dougancil | last post by:
I have the following query that was written by someone else that I need help converting to a SQL query, can anyone assist me with this? Thank you SELECT .Last_First_Name, .Employee_Number, ...
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?
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
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,...
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...
0
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.