Home All Groups Group Topic Archive Search About

day/month/year parts of a date

Author
19 Nov 2007 2:37 PM
Guy Cohen
Hello
how do I get the day/month/year part of a date in vb.net?

sample in vb6:
day(13/10/2001) = 13
month(13/10/2001) = 10
year(13/10/2001) = 2001

Thanks
Guy

Author
19 Nov 2007 2:46 PM
Tom Shelton
On Nov 19, 7:37 am, Guy Cohen <GuyCo***@discussions.microsoft.com>
wrote:
> Hello
> how do I get the day/month/year part of a date in vb.net?
>
> sample in vb6:
> day(13/10/2001) = 13
> month(13/10/2001) = 10
> year(13/10/2001) = 2001
>
> Thanks
> Guy

While, you have the visual basic DataPart function:

   Dim dt As New Date(2001, 10, 13) ' or As New DateTime(2001, 10, 13)

   Console.WriteLine(DatePart(DateInterval.Day, dt))
   Console.WriteLine(DatePart(DateInterval.Month, dt))
   Console.WriteLine(DatePart(DateInterval.Year, dt))

Or you can just use the standard date properties:

   Console.WriteLine(dt.Day)
   Console.WriteLine(dt.Month)
   Console.WriteLine(dt.Year)

--
Tom Shelton
Author
19 Nov 2007 2:48 PM
Guy Cohen
I think I found it...
DateTime.Day was converted to DateAndTime.Day...
Show quoteHide quote
:)
Guy

"Guy Cohen" wrote:

> Hello
> how do I get the day/month/year part of a date in vb.net?
>
> sample in vb6:
> day(13/10/2001) = 13
> month(13/10/2001) = 10
> year(13/10/2001) = 2001
>
> Thanks
> Guy
Author
20 Nov 2007 4:42 AM
Cor Ligthert[MVP]
You were sending at the same time as Tom, for the Google searchers. Take the
answer from Tom.

Cor