Link to home
Start Free TrialLog in
Avatar of sath350163
sath350163

asked on

First millisecond and Last millisecond in a day

How to get the very first millisecond and very last millisecond in a day in Oracle?

Thanks!
Avatar of MikeOM_DBA
MikeOM_DBA
Flag of United States of America image

You could use timestamp:

SELECT TO_CHAR(SYSTIMESTAMP,'DD-MON-YYYY HH24.MI.SS.FF') FROM DUAL;

Open in new window

Avatar of sath350163
sath350163

ASKER

Thanks for the response.

I eseentially need to retrieve records from the very first millisecond in a day (say today) until vers last millisecond of today.
Can you please tell me how that can be achieved?
SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.

My table stores the date time as Number which is in milliseconds.
So timestamp_column equivalent column in my schema is a NUMBER column.

Here is a sample Number value representing a Date Time: 1359651194334

select * from table where MilliSecs_Number_column >= trunc(systimestamp) and < trunc(systimestamp+1);

So,  how do I convert the MilliSecs_Number_column to DATE with Timestamp in the SELECT sql?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not sure. It is being stamped by JAVA code.

On converting the Number in Milliseconds to Date, I get 1/31/2013 4:53:14 PM.
SELECT TO_DATE('01/01/1970 00:00:00','DD/MM/YYYY HH24:MI:SS') + (1359651194334  /1000/60/60/24) from dual;

Open in new window

Your approach works. Thanks.

In the mean time, I also found another approach which is essentially giving me the same result:
select * 
  from table 
 where TO_DATE('1970-01-01', 'YYYY-MM-DD') + (1359651194334  /1000/60/60/24) >= trunc(systimestamp) 
   and TO_DATE('1970-01-01', 'YYYY-MM-DD') + (1359651194334  /1000/60/60/24) < trunc(systimestamp+1);  

Open in new window

What do you think about this approach?
Thanks!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good point. I'll have to discuss with the developers on that.
Thanks to both slighwv and MikeOM_DBA for the help.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome. Thanks for the findings.