Link to home
Start Free TrialLog in
Avatar of rehman123
rehman123

asked on

How to Convert string into date

hello i am using 2 textbox like t1 and t2

in t1 i have 31/03/2006 and in t2 i have 30/04/2006

i want to insert these values in date column in the tables.

table test
 t1 date
t2 date

Please suggest me and help me
Thanks in Advance.

Avatar of albinjoseph
albinjoseph
Flag of India image

Hi

Please find the below code.

SimpleDateFormat sdf= new SimpleDateFormat("MM/dd/yyyy");
Date dt = sdf.parse(tr.value);

Albin Joseph
*advertising removed by Netminder 31 Aug 2006*
Avatar of YZlat
what language and what database are you using?

If Access, then when building your sql query, put # signs arounf the date field. And if SQL Server, then put sinle quotes:

for Access:

sql="INSERT INTO test(t1,t2) VALUES (#" & t1.Text & "#,#" & t2.Text & "#)"

for SQL Server:

sql="INSERT INTO test(t1,t2) VALUES ('" & t1.Text & "','" & t2.Text & "')"

Avatar of rehman123
rehman123

ASKER

yZLAT

I am using Asp.net and Oracle as a Database .
Same way i am trying but it is giving error that not a date format .

[InvalidCastException: Cast from string "31/03/2006" to type 'Date' is not valid.]

please suggest
Try changing the date format, I know i get this eror regularly in MS SQL when trying to use xx/xx/xxxx
Instead I have to format the date like SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
Give that a shot, not sure if its the same for oracle or not.
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Session.LCID = 2057

type this code in the page_load event
and use cdate function it will work
mclSql3 = "insert into fs_separation_details ( fsd_id, fsd_emp_id, fsd_issued_date,fsd_ic_id,fsd_bonus_amount"
        mclSql3 = mclSql3 & " ,fsd_hod_discussion,FSD_LAST_WORKING_DATE)"
        mclSql3 = mclSql3 & " values(seq_fsd.NEXTVAL, '" & lblempid.Text & "',sysdate,'" & cmd_sep_reason.SelectedValue & "','" & LblBonus.Text & "'"
       mclSql3 = mclSql3 & ",'" & txthod.Text & "', to_date(‘" & CDate(txtLwd.Text) & "’,’dd/mm/yyyy’) )"


Any way thanks a lot .