Solved

Read datetime field in as Date in oracle sql

Posted on 2014-04-01
4
532 Views
Last Modified: 2014-04-01
Experts,

I have a field that is datetime on an Oracle table.  I would like to read the field in as date in a proc sql statement.  

Can this be done?
0
Comment
Question by:morinia
  • 3
4 Comments
 
LVL 23

Accepted Solution

by:
paquicuba earned 350 total points
ID: 39969530
Yes, you can do it explicitly or you can let Oracle handle the conversion for you:

declare
l_date date;
begin
select systimestamp into l_date from dual;
dbms_output.put_line(l_date);
dbms_output.put_line(trunc(l_date));
dbms_output.put_line(to_char(l_date,'MM/DD/YYYY'));
end;
/
0
 
LVL 23

Expert Comment

by:paquicuba
ID: 39969537
If you have a varchar2 variable, then you can format the date/timestamp as you like:

DECLARE
l_date VARCHAR2(4096);
BEGIN
SELECT to_char(SYSTIMESTAMP,'DD-MON-RR') INTO l_date FROM dual;
dbms_output.put_line(l_date);
END;
/
0
 

Author Comment

by:morinia
ID: 39969556
Experts,

The date is coming in as part of a Select statement.  ie

Select memberid
       ,member,lname
       ,member_fname
       ,member_dob
From members.

Can member_dob be formatted in this type of query.  Some languages you can use datepart(d, member_dob)
0
 
LVL 23

Expert Comment

by:paquicuba
ID: 39969639
OK. What exactly do you want to display?

Run the following query and let me know if anything looks like it:

WITH members AS
(
 SELECT
    1 memberid
   ,'UNCLEAR' member_lname
   ,'MORINIA' member_fname
   ,SYSDATE - INTERVAL '20' YEAR member_dob
  FROM dual
)
SELECT memberid
       ,member_lname
       ,member_fname
       ,to_char(member_dob,'MM/DD/YYYY') member_dob_1
       ,to_char(member_dob,'DD-MON-RR') member_dob_2
       ,EXTRACT(DAY FROM member_dob) member_dob_day
       ,EXTRACT(MONTH FROM member_dob) member_dob_month
       ,EXTRACT(YEAR FROM member_dob) member_dob_year
FROM members
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now