Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net

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

like image 571
Nandini Avatar asked Feb 26 '10 07:02

Nandini


2 Answers

DateTime
    .ParseExact("20091023", "yyyyMMdd", CultureInfo.InvariantCulture)
    .ToString("yyyy/MM/dd")
like image 128
Darin Dimitrov Avatar answered Oct 05 '22 02:10

Darin Dimitrov


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.

like image 26
Hans Kesting Avatar answered Oct 05 '22 00:10

Hans Kesting