4

i have full date(with time). But i want only millisecond from date.

please tell me one line solution

for example: date= 2016/03/16 10:45:04.252 i want this answer= 252

i try to use this query.

SELECT ADD_MONTHS(millisecond, -datepart('2016/03/16 10:45:04.252', millisecond),
     '2016/03/16 10:45:04.252') FROM DUAL;

but i'm not success.

3 Answers 3

11

i have full date (with time)

This can only be done using a timestamp. Although Oracle's date does contain a time, it only stores seconds, not milliseconds.


To get the fractional seconds from a timestamp use to_char() and convert that to a number:

select to_number(to_char(timestamp '2016-03-16 10:45:04.252', 'FF3'))
from dual;
4
  • Thanks you for efforts.i got my answer Commented Dec 12, 2019 at 10:37
  • This is the cleanest answer.
    – Seymour
    Commented Apr 9, 2020 at 14:30
  • What about EXTRACT( timestamp_value, MILLISECOND ) ? (EDIT: Ah, that's only in "Oracle Big Data", not Oracle Database, even in version 21c, that's crazy...)
    – Dai
    Commented Feb 18, 2021 at 10:48
  • I noticed that this works in Oracle 11g: SELECT ( timestamp_value - CAST( ValidFrom AS timestamp(0) ) ) AS ms FROM tableName however the type of ms is still timestamp(n).
    – Dai
    Commented Feb 18, 2021 at 10:55
0
SELECT 
TRUNC((L.OUT_TIME-L.IN_TIME)*24)           ||':'||
TRUNC((L.OUT_TIME-L.IN_TIME)*24*60)        ||':'||
ROUND(CASE WHEN ((L.OUT_TIME-L.IN_TIME)*24*60*60)>60 THEN ((L.OUT_TIME-L.IN_TIME)*24*60*60)-60 ELSE ((L.OUT_TIME-L.IN_TIME)*24*60*60) END ,5) Elapsed
FROM XYZ_TABLE
1
  • 1
    code only answers, while being correct, are not really useful to understand the solution. Please consider adding some text explaining what you have done and what the code means
    – John Doe
    Commented Nov 14, 2019 at 12:13
0

The millisecond of the day:

  select to_number(to_char(tms_now, 'sssss') || to_char(tms_now, 'ff3')) day_millisecond
    from (select systimestamp as tms_now from dual);

The microsecond of the day:

  select to_number(to_char(tms_now, 'sssss') || to_char(tms_now, 'ff')) day_microsecond
    from (select systimestamp as tms_now from dual);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.