Create this UDT somewhere:
create function <your_util_library>.epoch_time(seconds integer default null)
returns integer
language c
external name 'QSYS/QC2UTIL1(time)'
parameter style general with nulls
no sql
not fenced
not deterministic
no external action;
And then you can use it like this:
select <your_util_library>.epoch_time() from sysibm.sysdummy1
Coy Krill
Core Processing Administrator/Analyst
Washington Trust Bank
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Krill, Coy
Sent: Tuesday, November 10, 2015 15:04
To: Midrange Systems Technical Discussion
Subject: RE: DB2: Generating epoch time
Importance: Low
Scratch all that, the TIMESTAMPDIFF is returning an estimate even when requesting seconds as the interval, so this results in the epoch time being off by a two full weeks on my box. Best bet might be a UDF wrapper around the C time() runtime function.
I vaguely remember TIMESTAMPDIFF biting me the same way every few years when I try to use it again as I forget it's an estimate.
Coy Krill
Core Processing Administrator/Analyst
Washington Trust Bank
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Krill, Coy
Sent: Tuesday, November 10, 2015 14:27
To: Midrange Systems Technical Discussion
Subject: RE: DB2: Generating epoch time
Importance: Low
Forgot you have to add in your utc time offset in seconds as well. This would be better as a UDF since you have to parse that up into hours and minutes on the off chance you're in a timezone that uses offsets that also have minutes.
Coy Krill
Core Processing Administrator/Analyst
Washington Trust Bank
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Krill, Coy
Sent: Tuesday, November 10, 2015 13:51
To: Midrange Systems Technical Discussion
Subject: RE: DB2: Generating epoch time
Importance: Low
timestampdiff(2, cast(current_timestamp-cast('1970-01-01 00:00:00.000000' as timestamp) as char(22)))
Coy Krill
Core Processing Administrator/Analyst
Washington Trust Bank
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of rob@xxxxxxxxx
Sent: Tuesday, November 10, 2015 13:09
To: midrange-l@xxxxxxxxxxxx
Subject: DB2: Generating epoch time
Importance: Low
Is there some way to generate the epoch time in SQL?
I tried
values generate_unique()
but that was blank.
And I tried the ancient
select generate_unique() from sysibm.sysdummy1 but that worked the same
I took a wag at
values cast(generate_unique() as char(30)) but that wasn't any better.
This was a little different
values generate_unique(), timestamp(generate_unique()) ....+....1....+....2....+.
VALUES
++++++++++++++++++++++++++
2015-11-10-21.04.02.786923
******** End of data ***
Before I never even got the plus signs.
I was pointed to this epoch site by IBM
http://www.epochconverter.com/?cm_mc_uid=04943014784214468222669&cm_mc_sid_50200000=1447188011
Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1 Group Dekko Dept 1600 Mail to: 2505 Dekko Drive
Garrett, IN 46738
Ship to: Dock 108
6928N 400E
Kendallville, IN 46755
http://www.dekko.com
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at
http://archive.midrange.com/midrange-l.
---------------------------------------------------------------------
This electronic mail message and any attachments may contain confidential or privileged information and is intended for use solely by the above-referenced recipient. Any review, copying, printing, disclosure, distribution, or other use by any other person or entity is strictly prohibited under applicable law. If you are not the named recipient, or believe you have received this message in error, please immediately notify the sender by replying to this message and delete the copy you received
---------------------------------------------------------------------
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at
http://archive.midrange.com/midrange-l.
---------------------------------------------------------------------
This electronic mail message and any attachments may contain confidential or privileged information and is intended for use solely by the above-referenced recipient. Any review, copying, printing, disclosure, distribution, or other use by any other person or entity is strictly prohibited under applicable law. If you are not the named recipient, or believe you have received this message in error, please immediately notify the sender by replying to this message and delete the copy you received
---------------------------------------------------------------------
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at
http://archive.midrange.com/midrange-l.
---------------------------------------------------------------------
This electronic mail message and any attachments may contain confidential or privileged information and is intended for use solely by the above-referenced recipient. Any review, copying, printing, disclosure, distribution, or other use by any other person or entity is strictly prohibited under applicable law. If you are not the named recipient, or believe you have received this message in error, please immediately notify the sender by replying to this message and delete the copy you received
---------------------------------------------------------------------
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at
http://archive.midrange.com/midrange-l.
---------------------------------------------------------------------
This electronic mail message and any attachments may contain confidential or privileged information and is intended for use solely by the above-referenced recipient. Any review, copying, printing, disclosure, distribution, or other use by any other person or entity is strictly prohibited under applicable law. If you are not the named recipient, or believe you have received this message in error, please immediately notify the sender by replying to this message and delete the copy you received
---------------------------------------------------------------------
As an Amazon Associate we earn from qualifying purchases.