convert date and time formats

M

Mythran

romy said:
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
 
A

Al Reid

romy said:
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")
 
A

Armin Zingler

romy said:
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
 
R

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
 
C

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
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
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.
 
C

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
 
A

Armin Zingler

Herfried K. Wagner said:
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
 
H

Herfried K. Wagner [MVP]

Cor,

Cor Ligthert said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top