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.
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.
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 & "')"
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 & "')"
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
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.
Instead I have to format the date like SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-
Give that a shot, not sure if its the same for oracle or not.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_LA ST_WORKING _DATE)"
mclSql3 = mclSql3 & " values(seq_fsd.NEXTVAL, '" & lblempid.Text & "',sysdate,'" & cmd_sep_reason.SelectedVal ue & "','" & LblBonus.Text & "'"
mclSql3 = mclSql3 & ",'" & txthod.Text & "', to_date(‘" & CDate(txtLwd.Text) & "’,’dd/mm/yyyy’) )"
Any way thanks a lot .
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,
mclSql3 = mclSql3 & " ,fsd_hod_discussion,FSD_LA
mclSql3 = mclSql3 & " values(seq_fsd.NEXTVAL, '" & lblempid.Text & "',sysdate,'" & cmd_sep_reason.SelectedVal
mclSql3 = mclSql3 & ",'" & txthod.Text & "', to_date(‘" & CDate(txtLwd.Text) & "’,’dd/mm/yyyy’) )"
Any way thanks a lot .
Please find the below code.
SimpleDateFormat sdf= new SimpleDateFormat("MM/dd/yy
Date dt = sdf.parse(tr.value);
Albin Joseph
*advertising removed by Netminder 31 Aug 2006*