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!
sath350163Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
slightwv (䄆 Netminder)Connect With a Mentor Commented:
>>What do you think about this approach?

Isn't that what I posted?

1000*60*60*24 = 86400000

As for what I think:  If what is stored as a number converts to the correct date using the formula, I think it is a great idea.

You need to get with the developers to confirm what they are storing and what it resolves to.

If 1359651194334  doesn't mean 1/31/2013 4:53:14 PM, then this is a horrible idea since the conversion is wrong.

Basically you need to get from the developers or someone the date they start counting milliseconds from.  Then use that to seed the calculation.

If I was to bet money on it, I would guess unix epoch, 01/01/1970.
0
 
MikeOM_DBACommented:
You could use timestamp:

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

Open in new window

0
 
sath350163Author Commented:
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?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
slightwv (䄆 Netminder)Connect With a Mentor Commented:
select * from table where timestamp_column >= trunc(systimestamp) and < trunc(systimestamp+1);

You could use sysdate in place of systimestamp since trunc strips the time portion of either.
0
 
sath350163Author Commented:
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?
0
 
slightwv (䄆 Netminder)Connect With a Mentor Commented:
>>Here is a sample Number value representing a Date Time: 1359651194334

What date/time does that represent?

If unix epoch, there are a TON of links out there on converting these to Oracle:


For example:
http://www.experts-exchange.com/Database/Oracle/Q_27681819.html#a37861961

select * from table where TO_DATE('1970-01-01', 'YYYY-MM-DD') + MilliSecs_Number_column/ 86400000 >=
trunc(systimestamp) and TO_DATE('1970-01-01', 'YYYY-MM-DD') + MilliSecs_Number_column/ 86400000 < trunc(systimestamp+1);
0
 
sath350163Author Commented:
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!
0
 
sath350163Author Commented:
Good point. I'll have to discuss with the developers on that.
0
 
sath350163Author Commented:
Thanks to both slighwv and MikeOM_DBA for the help.
0
 
PortletPaulConnect With a Mentor freelancerCommented:
java does use 1st Jan 1970
http://docs.oracle.com/javase/1.4.2/docs/api/java/sql/Timestamp.html

I suggest converting the date boundaries into a number that can be directly compared to the java timestamp data in your table, like this:


select
*
from table1
where (
      /* for "yesterday" */
      table1.java_timestamp >= ((truc(sysdate-1) - to_date('1970-01-01', 'YYYY-MM-DD')) * 86400000)
       and
      table1.java_timestamp < ((truc(sysdate) - to_date('1970-01-01', 'YYYY-MM-DD')) * 86400000)
      )
   

Open in new window

0
 
sath350163Author Commented:
Awesome. Thanks for the findings.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.