DateTime Question?

  • Thread starter Thread starter Vai2000
  • Start date Start date
V

Vai2000

Hi All, I am getting date in yyyyMMdd format.How do I parse it?
string s="20050302";
need to convert this to DateTime object

TIA
 
Vai2000 said:
Hi All, I am getting date in yyyyMMdd format.How do I parse it?
string s="20050302";
need to convert this to DateTime object

Use DateTime.ParseExact:

DateTime dt = DateTime.ParseExact (s, "yyyyMMdd",
CultureInfo.InvariantCulture);
 
try this:

DateTimeFormatInfo myDTFI = new DateTimeFormatInfo();
myDTFI.DateSeparator = string.Empty;
myDTFI.FullDateTimePattern = mask;
string s = "20050302";
DateTime d = DateTime.ParseExact(s, myDTFI);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Date formatting on DateTime? 4
DateTime 3
SqlDateTime and DateTime 2
Convert this string to a datetime 1
Parse DateTime and Boolean 6
Parsing DateTime 10
Time conversion 2
DateTime.now - 30 (days) 2

Back
Top