Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert datetime field to just a date field in SQL (Oracle)

I've seen a few answers to questions similar to mine but I cannot get them to work. I have several date fields in my query that return the date and time like such 7/1/2014 12:00:00 AM. Is there a way I can just have the fields show 7/1/2014?

SELECT DISTINCT
C.RECEIPTDATE,
(I.CLIENTID ||' - '||PO.CLIENTNAME) AS CLIENT,
D.INVOICEID,
D.SVCFROMDATE,
D.SVCTODATE,
D.SVCCODE
FROM M_EQP_ORDERS
WHERE.....

I basically would like to cut down the two date fields to the shorter date format minus the time.

Thanks in advance!

like image 513
tia97 Avatar asked Sep 26 '14 14:09

tia97


2 Answers

Just use the function TRUNC.

SELECT DISTINCT
TRUNC(C.RECEIPTDATE),
(I.CLIENTID ||' - '||PO.CLIENTNAME) AS CLIENT,
D.INVOICEID,
TRUNC(D.SVCFROMDATE),
TRUNC(D.SVCTODATE),
D.SVCCODE
FROM M_EQP_ORDERS
WHERE.....
like image 85
Vulcronos Avatar answered Sep 28 '22 01:09

Vulcronos


Use to_char function:

SELECT DISTINCT
to_char(C.RECEIPTDATE,'DD/MM/YYYY'),
(I.CLIENTID ||' - '||PO.CLIENTNAME) AS CLIENT,
D.INVOICEID,
D.SVCFROMDATE,
D.SVCTODATE,
D.SVCCODE
FROM M_EQP_ORDERS
WHERE.....
like image 45
Aramillo Avatar answered Sep 27 '22 23:09

Aramillo