-4

I hava java program , the program get table 'Employees' from oracle Database 11G

the problem is ,

java program get the Hire_Date Column in this format “YYYY-MM-DD 00:00:00.0”

I want get the date in this format “YYYY-MM-DD"

How can I solve This Problem ?

the photo will explian the problem

https://i.stack.imgur.com/ip3RR.png

1 Answers1

3

You can do this as part of your select statement:

SELECT TO_CHAR(HIRE_DATE, 'DD-MON-YYYY') HIRE_DATE_TRUNC FROM EMPLOYEES;

Use of to_char to format dates is described here. Alternatively, you could use a SimpleDateFormat to do the same thing in Java after the data has been extracted:

SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd");

Date d = new Date();
String formatted = sdf.format(d);
System.out.println(formatted);
hugh
  • 2,237
  • 1
  • 12
  • 25