tags:

views:

49

answers:

2

Hi,

I have a date like this:- 20091023 i have to convert it to a suitable format so that i can insert it into the database.For this firstly i have to convert it to 2009/10/23.How can i do this?

+8  A: 
DateTime
    .ParseExact("20091023", "yyyyMMdd", CultureInfo.InvariantCulture)
    .ToString("yyyy/MM/dd")
Darin Dimitrov
+1  A: 

If you want to insert the date into a database, then don't convert to a different string: convert it to a DateTime value (using ParseExact or TryParseExact). Then use a parameter (of a date type) in the query to use this value in the database.

Hans Kesting