date formt

N

nik

I'm having problems with date formatting...

this works:
string testD = "04-08-2004";
DateTime dt = DateTime.Parse(testD);

this doesn't:
string m_reviewDate = getPHContent.GetContent
("MDReviewDate", m_currentPosting);
DateTime dt = DateTime.Parse(m_reviewDate);

Error: The string was not recognized as a valid Date Time.

m_reviewDate is just getting content out of a CMS
placeholder, the format is the same as the testD string.

Any ideas?
 
M

Mark Johnson

This may depend on the CulureInfo that is activ at the time :
// Initialize culture info for current Mashine
ci_CultureInfo =
(System.Globalization.CultureInfo)System.Globalization.CultureInfo.CurrentUI
Culture.Clone();
s_Temp =
String.Format("{0,-10} -",ci_CultureInfo.DateTimeFormat.ShortDatePattern);

Results should look like this
- dd-MM-yyyy (4 August 2004)

If you are recieving :
- yyyy-MM-dd (2004 August 04)
- dd/MM/yyyy (4 of August 2004)
- M/d/yyyy (April 8 2004)
- d/MM/yyyy (4 August 2004)
- dd.MM.yyyy (4 August 2004)

this function may fail.

Mark Johnson, Berlin Germany
(e-mail address removed)
 

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

Top