Work with dates and times in a table

Asked

Viewed 32 times

0

I created a diagram of a gym that has schedules and days, also created two tables on Oracle, which are these:

create table dia_semana (
coddia number (6) primary key,
dia DATE);


create table horario (
codhorario number (8) primary key,
horainicio ,
horafim );

Obviously they are not finished.

The type of data DATE allows data display in format YYYY-MM-DD am I correct?

How I would make him show in Brazilian format?

I would also like to know if there is any datatype that only prints data in time format and not date/time, if any, which?

1 answer

0


Data type DATE allows data display in format YYYY-MM-DD I am correct?

Yeah and no, the guy DATE stores a date in the database, so viewing will depend on who is dealing with this data.

How I would make him show in Brazilian format?

You can convert your data from date for varchar and show the dice the way you want, just use the function to_char

Example:

to_char(horainicio,'dd/mm/rrrr');

I would also like to know if there is any datatype that prints only data in time format and not date/time, if any, which?

Printing is different from storing, but I understand your point of view. At Oracle can not store only the time... Unless you want to save this information in text... then could use the varchar2, however there are a number of disadvantages in doing this and I do not recommend.

To print only the hour, you can also use the function to_char.

Example:

to_char(horainicio,'hh24:mi');
  • Where exactly would I implement this to_char, something like that? dia DATE to_char (dia, 'DD/MM/AAAA');

  • In your diagram will not change anything, keep putting the date and time fields with the type DATE. This would be in the query of your table, through a SELECT.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.