toDate conversions

  • Thread starter Thread starter bios
  • Start date Start date
B

bios

can I convert a date string like 20031231105718
which is in format yyyymmddhhmmss into a normal date string?

can I say someting like date format yyyymmddhh:24mmss
then make that string a date and then convert?

thanks a bunch
 
Sure you can convert the string into DateTime by specifing the expected
format, then convert to any format you want

Here is a small example, hope it helps!
string strMyDateTime = "20031231105718";

System.IFormatProvider format =

new System.Globalization.CultureInfo("en-US", true);


string expectedformat = "yyyyMMddHHmmss";

System.DateTime myDateTime =

System.DateTime.ParseExact(strMyDateTime,

expectedformat,

format,

System.Globalization.

DateTimeStyles.AllowWhiteSpaces);

Console.WriteLine(myDateTime.ToString () );
 
Thanks. Code works nicely.
:)


jennyq said:
Sure you can convert the string into DateTime by specifing the expected
format, then convert to any format you want

Here is a small example, hope it helps!
string strMyDateTime = "20031231105718";

System.IFormatProvider format =

new System.Globalization.CultureInfo("en-US", true);


string expectedformat = "yyyyMMddHHmmss";

System.DateTime myDateTime =

System.DateTime.ParseExact(strMyDateTime,

expectedformat,

format,

System.Globalization.

DateTimeStyles.AllowWhiteSpaces);

Console.WriteLine(myDateTime.ToString () );
 
Back
Top