Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Let me know, I want to save string value in database as smalldatetime format.My string value format is MM/dd/yyyy.How can i change string(MM/dd/yyyy) to smalldatetime format for save in database?


Regard,
Theingi Win
Posted
Updated 17-Apr-11 23:21pm
v2

 
Share this answer
 
Comments
Theingi Win 18-Apr-11 23:32pm    
Thanks Sandeep Mewara! for your answer.
Theingi Win
Sandeep Mewara 19-Apr-11 0:15am    
Good to know it helped.
try this link

Click[^]
 
Share this answer
 
Comments
Theingi Win 18-Apr-11 5:10am    
Thanks mahen25! for your answer

I don't want to select, i want to save my string(MM/dd/yyyy) format Date(smalldatetime) field in database.If you have other answer ,Please give me.
Regard,
Theingi Win
Here you go..
string dateString = "01/31/2011";
string pattern = "MM/dd/yyyy";
DateTime parsedDate = DateTime.Now;
            
if (DateTime.TryParseExact(dateString, pattern, null, DateTimeStyles.None, out parsedDate)){
   //parsedDate.ToShortDateString()
   //ready to be used as ShorDateString
   //....
}


Good luck!
 
Share this answer
 
Comments
Theingi Win 18-Apr-11 23:31pm    
Thanks Pong D.Panda! for your answer.
Theingi Win
If you have datetime format for date you want to save then it save as datetime default positions it treat as 00. But for select with specific format then use,-
convert(varchar,date,103) here '103' is the format. There are other format are available also. like 101,102,104, and others.
 
Share this answer
 
Comments
Theingi Win 18-Apr-11 23:32pm    
Thanks Prasanta_Prince! for your answer.
Theingi Win
Prasanta_Prince 23-Apr-11 6:44am    
Good to know it works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900