Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing milliseconds from a oracle tmstmp field

I have a TIMESTAMP(6) field in Oracle and I need to remove the millisecond component from the time.

For example I have

10/20/2014 10:34:06.356000 AM

and I would like to remove the milliseconds so that I have

10/20/2014 10:34:06 AM

Do you know the best way to do this?

Thank you!

like image 336
user3022875 Avatar asked Dec 26 '14 15:12

user3022875


People also ask

How do I remove milliseconds from a TIMESTAMP?

Use the setSeconds() method to remove the seconds and milliseconds from a date, e.g. date. setSeconds(0, 0) . The setSeconds method takes the seconds and milliseconds as parameters and sets the provided values on the date.

Does Oracle TIMESTAMP have milliseconds?

Oracle date data types do not support milliseconds but Oracle timestamps do.

How do I remove the TIMESTAMP from a date in SQL Developer?

You can try using TRUNC() function. --- TRUNC(date_field)....in order to remove Timestamp. iif( is_date ... ( TO_CHAR(Daterec,' DD-MON-YYYY'').


2 Answers

How about this?

select cast(col as timestamp(0))

EDIT:

The easiest way to avoid rounding is to use trunc() or to subtract half a second:

select cast(col - 0.5/(24*60*60) as timestamp(0))
like image 57
Gordon Linoff Avatar answered Nov 15 '22 09:11

Gordon Linoff


try this

SELECT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "NOW"
FROM DUAL;

if you need 12-hour date format

SELECT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH:MI:SS AM') "NOW"
FROM DUAL;

SQL FIDDLE

like image 29
HaveNoDisplayName Avatar answered Nov 15 '22 08:11

HaveNoDisplayName