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 > Query to Get Midningt timestamp

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-12, 19:37
aramnaujam aramnaujam is offline
Registered User
 
Join Date: Jan 2012
Posts: 2
Query to Get Midningt timestamp

How do i get midnight timestamp for yesterday? I need to select all the records which was submitted before midnight.
Reply With Quote
  #2 (permalink)  
Old 01-26-12, 20:35
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
midnight timestamp for yesterday
I'm not sure wheather it is '2012-01-27 00.00.00' or '2012-01-26 00.00.00', if today is '2012-01-27'.

If assumed the former, try ...
current_timestamp - MIDNIGHT_SECONDS(current_timestamp) SECONDS
or
TIMESTAMP(current_date)

If you want the latter,
minus one day from the expressions.

Last edited by tonkuma; 01-26-12 at 20:59. Reason: Correct first sample expression(Add "SECONDS")
Reply With Quote
  #3 (permalink)  
Old 01-26-12, 20:56
aramnaujam aramnaujam is offline
Registered User
 
Join Date: Jan 2012
Posts: 2
Quote:
I'm not sure wheather it is '2012-01-27 00.00.00' or '2012-01-26 00.00.00', if today is '2012-01-27'.

If assumed the former, try ...
current_timestamp - MIDNIGHT_SECONDS(current_timestamp)
or
TIMESTAMP(current_date)

If you want the latter,
minus one day from the expressions.
Today is 2012-01-26
I need '2012-01-26 00.00.00'

I got errors for both of these
select TIMESTAMP(current_date) from sysibm.sysdummy1
THE NUMBER OF ARGUMENTS SPECIFIED FOR TIMESTAMP IS INVALID. SQLCODE=-170, SQLSTATE=42605, DRIVER=3.58.81

select (current_timestamp - MIDNIGHT_SECONDS(current_timestamp)) from sysibm.sysdummy1
THE DATA TYPE, LENGTH, OR VALUE OF ARGUMENT 2 OF - IS INVALID. SQLCODE=-171, SQLSTATE=42815, DRIVER=3.58.81
Reply With Quote
  #4 (permalink)  
Old 01-26-12, 21:04
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
What DB2 version/release and platform OS are you using?

The corrected expressions worked on my DB2 9.7.5 on Windows.
Code:
------------------------------ Commands Entered ------------------------------
VALUES
( current_timestamp - MIDNIGHT_SECONDS(current_timestamp) SECONDS
, TIMESTAMP(current_date)
);
------------------------------------------------------------------------------

1                          2                  
-------------------------- -------------------
2012-01-27-00.00.00.585000 2012-01-27-00.00.00

  1 record(s) selected.
Reply With Quote
  #5 (permalink)  
Old 01-26-12, 21:13
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
The result of expression
current_timestamp - MIDNIGHT_SECONDS(current_timestamp) SECONDS
include subsecond difference.

It would be better to use latter expression
TIMESTAMP(current_date)

If your DB2 doesn't support it, try
TIMESTAMP( CHAR(current_date) )
Reply With Quote
Reply

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