Q
Problem solve Get help with specific problems with your technologies, process and projects.

Storing only time, not date

Please tell me how we can define the data type for the date field to store only time, not date, like hh24:mm.

I would say that I would still use the DATE datatype. But I would just set the day to be the same day. For instance, if I had to store "12:12", "13:13", and "09:59" into a table, I would probably use INSERT statements similar to the following:

INSERT INTO my_table VALUES TO_DATE('01/01/01 
'||'12:12','MM/DD/YY HH24:MI'); 
INSERT INTO my_table VALUES TO_DATE('01/01/01 
'||'13:13','MM/DD/YY HH24:MI'); 
INSERT INTO my_table VALUES TO_DATE('01/01/01 
'||'09:59','MM/DD/YY HH24:MI'); 

For More Information


Why would I do this? Because with this method, date arithmetic operations still work. You can compute the difference between two different values with just a subtraction operator, for instance. If date arithmetic is not important to you, then you may consider just storing these values in a character field.
This was last published in December 2002

Dig Deeper on Oracle database design and architecture

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close