MysorePak Posted June 26, 2015 Report Posted June 26, 2015 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
mindless Posted June 26, 2015 Report Posted June 26, 2015 if its oracle... you need to use TO_DATE function
Darling999 Posted June 26, 2015 Report Posted June 26, 2015 Ya convert on SQL server to date in oracle
shivakumar577 Posted June 26, 2015 Report Posted June 26, 2015 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?
MysorePak Posted June 26, 2015 Author Report Posted June 26, 2015 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?
shivakumar577 Posted June 26, 2015 Report Posted June 26, 2015 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");
shivakumar577 Posted June 26, 2015 Report Posted June 26, 2015 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
MysorePak Posted June 26, 2015 Author Report Posted June 26, 2015 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
kumar1984 Posted June 26, 2015 Report Posted June 26, 2015 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')
Recommended Posts