By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,226 Members | 1,166 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,226 IT Pros & Developers. It's quick & easy.

convert date and time formats

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a

"romy" <ro******@Powerup1.com> wrote in message
news:%2***************@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

Nov 21 '05 #2

P: n/a
"romy" <ro******@Powerup1.com> wrote in message news:%2***************@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
Nov 21 '05 #3

P: n/a
"romy" <ro******@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

Nov 21 '05 #4

P: n/a
"romy" <ro******@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/>

Nov 21 '05 #5

P: n/a
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
Nov 21 '05 #6

P: n/a
"Cor Ligthert" <no************@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/>

Nov 21 '05 #7

P: n/a
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


Nov 21 '05 #8

P: n/a
Cor,

"Cor Ligthert" <no************@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/>

Nov 21 '05 #9

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@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
Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.