convert date and time formats

  • Thread starter Thread starter Mythran
  • Start date Start date
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
 
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")
 
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
 
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
 
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
 
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.
 
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
 
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
 
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.
 
Back
Top