Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

date.parseExact

80 views
Skip to first unread message

mirek.le...@gmail.com

unread,
Feb 15, 2008, 2:19:37 PM2/15/08
to
Hi,
Could anyone help me with my problem, while i'm trying to parse my
data:

Dim data As Date = Date.ParseExact("11/11/2004", "dd/mm/yyyy",
System.Globalization.DateTimeFormatInfo.InvariantInfo)
System.Console.Out.WriteLine(data.ToString)
i got:

2004-01-11 00:11:00

Why the type is Datetime while i declared Date, and why the time is
set to 00:11?

Regards

Mirek

RobinS

unread,
Feb 17, 2008, 7:00:14 PM2/17/08
to
I recommend that you search MSDN for DateTime.ParseExact and "Custom
DateTime Format Strings".

Basically, your format string is wrong.

Dim data as DateTime = Date.ParseExact("11/11/2004","d", _
System.Globalization.DateTimeFormatInfo.InvariantInfo)

returns "11/11/2004 12:00:00 AM".

"d" stands for "short date", which is "mm/dd/yyyy" format in the US,
dd/mm/yyyy in the UK (etc) style.

The time is 00:11 because mm in your format string stands for minutes. If
you really want to be specific about the format string, use the right
entries:

Dim data = Date.ParseExact("11/11/2004", "dd/MM/yyyy", _
System.Globalization.DateTimeFormatInfo.InvariantInfo)

In .Net, DateTime is used for dates and times. If you only want one part,
you'll have to handle that in the formatting, or however you are using it.
They are always together.

RobinS.
GoldMail, Inc.
----------------------------------
<mirek.le...@gmail.com> wrote in message
news:2c4cb7df-853d-4716...@i7g2000prf.googlegroups.com...

0 new messages