Home All Groups Group Topic Archive Search About

convert date and time formats

Author
27 Jun 2005 4:40 PM
romy
It used to work in vb6. I don't know  the syntax in vb.net

current date and time....

format (cstr(date),"DDMMYY")

format(cstr(time),"HHMM")

thanks

Author
27 Jun 2005 3:51 PM
Mythran
"romy" <royal***@Powerup1.com> wrote in message
news:%23gi8U6yeFHA.220@TK2MSFTNGP12.phx.gbl...
> It used to work in vb6. I don't know  the syntax in vb.net
>
> current date and time....
>
> format (cstr(date),"DDMMYY")
>
> format(cstr(time),"HHMM")
>
> thanks
>

Dim date As DateTime = DateTime.Parse("August 10, 1980 10:10:23 AM")

date.ToString("ddMMyy")
date.ToString("hhmm")

HTH,
Mythran
Author
27 Jun 2005 4:00 PM
Al Reid
"romy" <royal***@Powerup1.com> wrote in message news:%23gi8U6yeFHA.220@TK2MSFTNGP12.phx.gbl...
> It used to work in vb6. I don't know  the syntax in vb.net
>
> current date and time....
>
> format (cstr(date),"DDMMYY")
>
> format(cstr(time),"HHMM")
>
> thanks
>
>

Dim sDate As String = Format(DateTime.Now, "ddMMyy")  OR

Dim sDate As String = Format(DateTime.Today, "ddMMyy")



Dim sTime As String = Format(DateTime.Now, "hhmm")

--

Al Reid
Author
27 Jun 2005 4:03 PM
Armin Zingler
"romy" <royal***@Powerup1.com> schrieb
> It used to work in vb6. I don't know  the syntax in vb.net
>
> current date and time....
>
> format (cstr(date),"DDMMYY")

Now.ToString("ddMMyy")

> format(cstr(time),"HHMM")

Now.ToString("HHmm")

Have a look at the Date date type and it's members, including shared
members. The type Date is exactly the same as the type System.DateTime.

- Current date and time: Date.Now (equal to
Microsoft.VisualBasic.DateAndTime.Now)
- Current date: Date.Today (equal to
Microsoft.VisualBasic.DateAndTime.Today)
- Current time: Date.TimeOfDay (same time as
Microsoft.VisualBasic.DateAndTime.TimeOfDay, but different data type)


Armin
Author
27 Jun 2005 4:28 PM
Herfried K. Wagner [MVP]
"romy" <royal***@Powerup1.com> schrieb:
> It used to work in vb6. I don't know  the syntax in vb.net
>
> current date and time....
>
> format (cstr(date),"DDMMYY")
>
> format(cstr(time),"HHMM")

'Dim s As String = date.ToString(<format>)'.  For a list of possible formats
take a look at this article:

..NET Framework Developer's Guide -- Date and Time Format Strings
<URL:http://msdn.microsoft.com/library/en-us/cpguide/html/cpconDateTimeFormatStrings.asp>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
27 Jun 2005 5:45 PM
Cor Ligthert
Romy,

Be aware that the article that Herfried is showing is (although a very good
article) based on the general system.net posibilities. Visual Basic has
strong methods for date and time extra above that. As Armin told already.

In my opinion is there no reason why VBNet programmers would not use the
full strenght of Visual.Basic net instead of that only the subset now showed
by Herfried in these pages.

Just my thought,

Cor
Author
27 Jun 2005 6:17 PM
Herfried K. Wagner [MVP]
"Cor Ligthert" <notmyfirstn***@planet.nl> schrieb:
> Be aware that the article that Herfried is showing is (although a very
> good article) based on the general system.net posibilities. Visual Basic
> has strong methods for date and time extra above that. As Armin told
> already.

Wake up, Cor.  We are talking about converting a date to a string only.
VB.NET's methods for doing that are not stronger than those provided by the
..NET Framework.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
27 Jun 2005 7:24 PM
Cor Ligthert
Herfried,

> Wake up, Cor.  We are talking about converting a date to a string only.
> VB.NET's methods for doing that are not stronger than those provided by
> the .NET Framework.

I wrote this expressely because you are writting this forever in this way
about other functions as Mid, Len, and whatever.

However when the "parse" comes than you have another opinion.

The CDate is not a *strong* command, however just like the ones you are
forever mentioning in other situations, (which I don't like because of the
First as indexer), do I find this one extremly handy. I have nothing to
remember beside four characters "CDate" and than it does everything
accoording the language/culture settings of a computer.

You write forever "why not use VB methods when there are VB methods". I
never understand why in this case a "system" method should be used as you
always tell.

:-)

Cor
Author
27 Jun 2005 7:49 PM
Herfried K. Wagner [MVP]
Cor,

"Cor Ligthert" <notmyfirstn***@planet.nl> schrieb:
>> Wake up, Cor.  We are talking about converting a date to a string only.
>> VB.NET's methods for doing that are not stronger than those provided by
>> the .NET Framework.
>
> I wrote this expressely because you are writting this forever in this way
> about other functions as Mid, Len, and whatever.

I use VB.NET's own functions whenever possible.

> However when the "parse" comes than you have another opinion.

I hardly ever parse a date without specifying a certain date format.
Typically in Windows Forms applications processing user input I prefer a
DateTimePicker control for choosing dates over a textbox and string parsing.
When reading dates from a file, I use 'DateTime.ParseExact' to make sure the
data is read the way I want it to be read on every system.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
27 Jun 2005 7:45 PM
Armin Zingler
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb
> I hardly ever parse a date without specifying a certain date format.
> Typically in Windows Forms applications processing user input I
> prefer a DateTimePicker control for choosing dates over a textbox
> and string parsing. When reading dates from a file, I use
> 'DateTime.ParseExact' to make sure the data is read the way I want
> it to be read on every system.


Of course! DateTimePicker! That's the solution! :-))


Armin