[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1911
  • Last Modified:

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.

0
rehman123
Asked:
rehman123
1 Solution
 
albinjosephCommented:
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*
0
 
YZlatCommented:
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 & "')"

0
 
rehman123Author Commented:
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
o0JoeCool0oCommented:
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.
0
 
YZlatCommented:
sql="INSERT INTO test(t1,t2) VALUES ('" & CDate(t1.Text) & "','" & CDate(t2.Text) & "')"
0
 
rehman123Author Commented:
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 .



 

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now