If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > current timestamp in UTC

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-17-11, 18:17
apboic apboic is offline
Registered User
 
Join Date: Jan 2011
Posts: 8
current timestamp in UTC

Hello,

Hi,
I was looking for a DB2 functions which was equivlent of GetUTCdate() from SQL SERVER.

I want to create a table with a timestamp column that has a default value of UTC timestamp.

I tried:
DbServerTime timestamp not null with DEFAULT current timestamp - current timezone

but this is incorrect.

Thank you.
Reply With Quote
  #2 (permalink)  
Old 02-15-11, 11:21
JAYANTA_DATTA JAYANTA_DATTA is offline
Registered User
 
Join Date: Oct 2004
Location: DELHI INDIA
Posts: 336
Considering your server timestamp in EST, you can try something like the following:

>db2 "create table test_timestamp (
Employee_Id smallint,
TS_EST timestamp with default current timestamp,
TS_UTC timestamp generated always as (TS_EST + 5 hours) )"

>db2 "select employee_id, TS_UTC from test_timestamp"

EMPLOYEE_ID TS_UTC
----------- ------- ----------------------
3311 2011-02-16-02.15.18.532000
__________________

Jayanta Datta
DB2 UDB DBA
IBM India, Global Delivery
New Delhi
Reply With Quote
  #3 (permalink)  
Old 02-15-11, 13:52
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
(deleted due to incorrect information)

Last edited by Stealth_DBA; 02-15-11 at 13:57.
Reply With Quote
  #4 (permalink)  
Old 02-15-11, 15:01
apboic apboic is offline
Registered User
 
Join Date: Jan 2011
Posts: 8
Thanks for the suggestion; i will use it. Surprised that I cannot do it with a single column.
Reply With Quote
  #5 (permalink)  
Old 02-15-11, 15:26
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Adding 5 hours only works when Daylight Savings Time is not in effect.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #6 (permalink)  
Old 02-15-11, 15:39
apboic apboic is offline
Registered User
 
Join Date: Jan 2011
Posts: 8
agreed. that is why i have tried with current timestamp - current timezone; but that syntax will not work at the DDL level.
Reply With Quote
  #7 (permalink)  
Old 02-17-11, 14:08
JAYANTA_DATTA JAYANTA_DATTA is offline
Registered User
 
Join Date: Oct 2004
Location: DELHI INDIA
Posts: 336
That's correct, + 5 hours willn't consider DST.

What you can do is to add a field in the table with datatype timestamp (e.g. TS_UTC), and then write an AFTER INSERT Trigger on the same table, which will update the TS_UTC field for every insert with values derived from "current timestamp - current timezone".
__________________

Jayanta Datta
DB2 UDB DBA
IBM India, Global Delivery
New Delhi
Reply With Quote
Reply

Tags
default, timestamp, utc

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On