I have a file from an 'older' system that has two text fields, one contains
the date, the other the time.
In the date field, I get for example the value 161009. The first 2 are day,
the next 2 are month, and the last 2 are year.
To get it into a date format that I can use, I tried the following (actdate
is a date type)
actdate = tday & "/" & tmonth & "/" & tyear
But this fails....
I have to do the same with the time (1356 = 13:56)
Any tips on how to do this ???
Thanks
actdate = new DateTime(dateAsString.SubString(4,2),
dateAsString.SubString(2,2), dateAsString.SubString(0,2),
timeAsString.SubString(0,2), timeAsString.SubString(2,2), 0)
Good luck,
Johnny J.
"Aussie Rules" <au...@nospam.com> skrev i meddelandet
news:uIorr1Ra...@TK2MSFTNGP05.phx.gbl...
Do you have Option Strict On? The code you posted will not work
because the DateTime constructor does not take strings as any of its
arguments. Instead, it would be better use the TryParseExact method:
Imports System.Globalization
Dim stringDate As String = "161009"
Dim stringTime As String = "1356"
Dim parsedDate As DateTime
Dim parsedTime As DateTime
If DateTime.TryParseExact(stringDate, "ddMMyy",
CultureInfo.InvariantCulture, DateTimeStyles.None, parsedDate) Then
MsgBox("Date was parsed successfully")
Else
MsgBox("Date was not parsed successfully")
End If
If DateTime.TryParseExact(stringTime, "HHmm",
CultureInfo.InvariantCulture, DateTimeStyles.None, parsedTime) Then
MsgBox("Time was parsed successfully")
Else
MsgBox("Time was not parsed successfully")
End If
Chris
But if you do that, then it will work...
Cheers,
Johnny J.
"Chris Dunaway" <duna...@gmail.com> skrev i meddelandet
news:fac846b1-c77b-49d4...@k9g2000vbl.googlegroups.com...
Although English is of course an invariant language is in my idea that extra
for Culture Invariant made for persons who never came on the continent.
Noting is enough in that, even on the continent is a day a day, a month a
month and a year a year.
Only somebody not common with languages would invent something like this and
only someone only speaking English would use it like you. Are you an
Englishman (I know it).
:-)
Cor
"Chris Dunaway" <duna...@gmail.com> wrote in message
news:fac846b1-c77b-49d4...@k9g2000vbl.googlegroups.com...
Your zenophobic rant simply reveals that you don't know how to use correctly
the options available in the TryParse method.
"Cor Ligthert[MVP]" <Notmyfi...@planet.nl> wrote in message
news:e%23aln9g...@TK2MSFTNGP02.phx.gbl...
The culture invariant is simply because that English has two ways of
representing a date MM-dd-yyyy and dd-MM-yyyy.
The most natively English speaking persons use the first variant.
However, if you tell that which variant culture variant is exactly used,
there is no need to tell which variant is used, some strange thinking of
many persons who know only the English language and think that it's the only
language on earth or that it is the major language.
"James Hahn" <jh...@yahoo.com> wrote in message
news:OmRbiska...@TK2MSFTNGP02.phx.gbl...
The whole point of CultureInfo.InvariantCulture is to allow the programmer
to define and enforce a format for dates as strings (such as the literal
ddmmyy as in this case) that will function properly regardless of any
changes made to a user's culture settings. It enforces a consistency that
ensures that dates stored as strings will always convert correctly
regardless of whether the user's culture is specified as a specific culture
or as the user's variation of a specific culture.
If you are seeing it a some form of conspiracy to make the default format of
mm/dd/yyyy universal then that is because you are using it incorrectly as
part of formatting dates for display. The only thing that
CultureInfo.InvariantCulture has to do with displaying dates is in assisting
the programmer to ensure that dates stored as strings are always displayed
exactly as the user's culture info settings require. And that is how it has
been used in the above example.
"Cor Ligthert[MVP]" <Notmyfi...@planet.nl> wrote in message
news:%23bs8UCo...@TK2MSFTNGP02.phx.gbl...