franco
franco

Reputation: 2047

insert and extract hour an minute from oracle

I work with oracle

I want to insert data which contains hour and minute

I have this column : DATE_ARCH

the type of this column is date

I have this java code which should insert date in this column

 transfers.setDateArch(new java.sql.Date(
                        System.currentTimeMillis()));

but when I try to extract hour and minute from DATE_ARCH

using this sql code :

select to_char(transfers.DATE_ARCH , 'HH:MM') from transfers where id_transfer='TR-300'

I have all time this value :

12:05

Updated :

I try with this code :

Timestamp t = new Timestamp(new Date().getTime());

                transfers.setDateArch(t);

I try to extract hour and minute using this code :

select to_char(transfers.DATE_ARCH , 'HH24:MI') from transfers where id_transfer='TR-258'

but I have in all case this value :

00:00

as I already said the type of DATE_ARCH is date

When I try in sql with :

  UPDATE transfers SET DATE_ARCH = SYSDATE

I have the correct value using

 select to_char(transfers.DATE_ARCH , 'HH24:MI') from transfers where id_transfer='TR-258'

now I want to know how can I insert date with hour and minute using java code

Upvotes: 0

Views: 411

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269503

You are correct. I do not know enough about the java interface to Oracle to know the right solution. But, your solution is inserting the date with no time. The expression:

to_char(transfers.DATE_ARCH , 'HH:MM')

is returning "12" because that is midnight and "05" because it is May. The correct expression for minutes is:

to_char(transfers.DATE_ARCH , 'HH:MI')

and for a 24-hour clock:

to_char(transfers.DATE_ARCH , 'HH24:MI')

I do not, alas, know how to fix the java code. But perhaps there is a DateTime method that you can use.

Upvotes: 1

Related Questions