Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on 

How to get the current date and Time upon oracle insert into a database table

How can I get the current date AND time ? I have experimented, but no success, because I am only getting the date and not the time.
Can someone help me out?

(CURRENT_TIMESTAMP and or TO_DATE(sysdate,'dd/mm/yyyy hh:mi:ss')   )

This is what I tried :

INSERT INTO MYTABLE (TABLENAME, DATETIME) VALUES ('Test',CURRENT_TIMESTAMP)

INSERT INTO MYTABLE (TABLENAME, DATETIME) VALUES ('Test',TO_DATE(sysdate,'dd/mm/yyyy hh:mi:ss'))
Oracle Database

Avatar of undefined
Last Comment
johnsone
Avatar of johnsone
johnsone
Flag of United States of America image

Do no put a TO_DATE function on SYSDATE.  It is already a date, there is no need to covert it.  In fact, what is happening is this:

TO_DATE(TO_CHAR(SYSDATE))

Based on your default NLS_DATE_FORMAT you are probably losing the time in that conversion.

If the data type of the column in the database is TIMESTAMP, then use SYSTIMESTAMP.

If the data type of the column in the table is DATE, then use SYSDATE.
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of brgdotnet
brgdotnet
Flag of United States of America image

ASKER

Based on your reply, I tried this, but it is not working? I am still getting only the date and not the time.

INSERT INTO MYTABLE (TABLENAME, DATETIME) VALUES ('Test',sysdate);
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

>>I am still getting only the date and not the time.

Just in case you missed my post:
How do you know?  When you select it, are you providing the correct format mask?
Avatar of brgdotnet
brgdotnet
Flag of United States of America image

ASKER

What do you mean sir? After I run the insert code, I then select everything from the table, and  I get the following : 09-MAR-17

SELECT * FROM MYTABLE

gives :

'Test', 09-MAR-17

Should my select be different, or should my insert sql statement be different? Thank you so much for working through this. I am just trying to understand.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of johnsone
johnsone
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Oracle Database
Oracle Database

Oracle is an object-relational database management system. It supports a large number of languages and application development frameworks. Its primary languages are SQL, PL/SQL and Java, but it also includes support for C and C++. Oracle also has its own enterprise modules and application server software.

81K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo