469,268 Members | 1,007 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

DateTime Question?

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
Nov 16 '05 #1
4 11158
Vai2000 <no****@microsoft.com> wrote:
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);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Try the DateTime.ParseExact() method.

--
Tim Wilson
..Net Compact Framework MVP

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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

Nov 16 '05 #3
Thanks ya all

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:eY**************@TK2MSFTNGP10.phx.gbl...
Try the DateTime.ParseExact() method.

--
Tim Wilson
.Net Compact Framework MVP

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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


Nov 16 '05 #4
try this:

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

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Grant Edwards | last post: by
6 posts views Thread by Carl | last post: by
8 posts views Thread by Jimmie | last post: by
3 posts views Thread by Andrew S. Giles | last post: by
8 posts views Thread by Alan Silver | last post: by
26 posts views Thread by Reny J Joseph Thuthikattu | last post: by
9 posts views Thread by Phil B | last post: by
4 posts views Thread by Philippe Martin | last post: by
5 posts views Thread by iulian.ilea | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.