How to insert a slash between a number in asp.net?

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 need to convert it to 2009/10/23. How can i do this?

+7
source share
2 answers
DateTime .ParseExact("20091023", "yyyyMMdd", CultureInfo.InvariantCulture) .ToString("yyyy/MM/dd") 
+8
source share

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

+1
source share

All Articles