Jump to content

Recommended Posts

Posted

I am getting date as a string "2015-05-20 10:00:49.0" from db in java method and now i need to send this date value to other field and run the query

 

select * from table  where date=?

 

how i can convert that string date value as date object to the other field

Posted

Ya convert on SQL server to date in oracle

Posted

String start_dt = "2011-01-01";
DateFormat formatter = new SimpleDateFormat("yyyy-MM-DD");
Date date = (Date)formatter.parse(start_dt);
SimpleDateFormat newFormat = new SimpleDateFormat("MM-dd-yyyy");
String finalString = newFormat.format(date);

 

thinking... this is what you wanna do?

Posted

Bhayya same chesanu but throws error

 

String st = "26-Jun-15 02:09:28";
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-DD"); 
    Date dat = (Date)formatter.parse(st);
    SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-DD");
    String finalString = newFormat.format(dat);
 
Exception in thread "main" java.text.ParseException: Unparseable date: "26-Jun-15 02:09:28"
at java.text.DateFormat.parse(Unknown Source)
 
i need to query with timestamp too but that field in DB is date... bec with timestamps i can delete the particular row

String start_dt = "2011-01-01";
DateFormat formatter = new SimpleDateFormat("yyyy-MM-DD");
Date date = (Date)formatter.parse(start_dt);
SimpleDateFormat newFormat = new SimpleDateFormat("MM-dd-yyyy");
String finalString = newFormat.format(date);

 

thinking... this is what you wanna do?

 

Posted

 

Bhayya same chesanu but throws error

 

String st = "26-Jun-15 02:09:28";
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-DD"); 
    Date dat = (Date)formatter.parse(st);
    SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-DD");
    String finalString = newFormat.format(dat);
 
Exception in thread "main" java.text.ParseException: Unparseable date: "26-Jun-15 02:09:28"
at java.text.DateFormat.parse(Unknown Source)
 
i need to query with timestamp too but that field in DB is date... bec with timestamps i can delete the particular row

 

 

baa nee question lo ne answer undhi anipisthundhi... three Ms undali... check the format of the string and match it with the date

 

DateFormat formatter = new SimpleDateFormat("yyyy-MMM-DD"); 

Posted

baa nee question lo ne answer undhi anipisthundhi... three Ms undali... check the format of the string and match it with the date

 

DateFormat formatter = new SimpleDateFormat("yyyy-MMM-DD"); 

DateFormat formatter = new SimpleDateFormat("DD-MMM-YY");

 

 

as per your string

Posted

Yeah bhayya..adhi chudaledhu but eppudu ee vachina output date value ne query ki ela set chesthamu.. correct me if i am wrong

 

INSERT_DT=to_date(?,'yyyy-mmm-dd hh:mm:ss')

DateFormat formatter = new SimpleDateFormat("DD-MMM-YY");

 

 

as per your string

 

Posted

select *,cast(date_column as date)

from abc.tablename

where cast(date_column as date)='2011-01-01'

Yeah bhayya..adhi chudaledhu but eppudu ee vachina output date value ne query ki ela set chesthamu.. correct me if i am wrong

 

INSERT_DT=to_date(?,'yyyy-mmm-dd hh:mm:ss')

 

×
×
  • Create New...