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

changing the date format in vb.net

P: n/a
When I copy a vb.net project using date formats from one PC with a windows
date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I
get errors.
How can I change for a while in the project the date format in vb.code (
not in Windows) and how can I find out which date format the PC Windows is
using.
Thanks for any response

Jun 14 '06 #1
Share this Question
Share on Google+
20 Replies


P: n/a
instead of using or changing the date, why not make your own?

Dim str as String = Now.Day & "/" & Now.Month & "/" & Now.Year

which gives:

dd/mm/yy

--
-iwdu15
Jun 14 '06 #2

P: n/a
That don't work
When i put in dd/mm/yy in my vb/.net program (on the other PC) is thinking
that is is yy/mm/dd so there is a error
There is some code for it with the word globalisation but I don't know the
code
Thanks any way

"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
news:17**********************************@microsof t.com...
instead of using or changing the date, why not make your own?

Dim str as String = Now.Day & "/" & Now.Month & "/" & Now.Year

which gives:

dd/mm/yy

--
-iwdu15

Jun 15 '06 #3

P: n/a
Andreas,

Strange, I can assure you that Ken and I exhange programs on regular base.

He is in the US and I in the EU. We never had any problem with datetime.

That would be crazy because in datetime there is not in a special culture.
It is a "long" which holds a counter of 100 nanoseconds ticks that started
(in Net) at the Christian calendar date 01/01/01 00:00:00. In other systems
the starting time and way it is done can be different.

But never try to convert the datetime to string formats with another reasons
than to show those.

I hope this helps,

Cor
"andreas" <an*****@pandora.be> schreef in bericht
news:Od**********************@phobos.telenet-ops.be...
When I copy a vb.net project using date formats from one PC with a windows
date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I
get errors.
How can I change for a while in the project the date format in vb.code (
not in Windows) and how can I find out which date format the PC Windows is
using.
Thanks for any response

Jun 15 '06 #4

P: n/a
When the date format is changed in windows (configuration panel) i got a
error on a different PC and on my own PC the dates with month = 25,13,..
and so on where not listened.
It depens likely on the settings mm/dd/yyyy or yyy/mm/dd.
And that is my question for a solution in vb.net to detect and to change
these PC settings
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oe**************@TK2MSFTNGP03.phx.gbl...
Andreas,

Strange, I can assure you that Ken and I exhange programs on regular base.

He is in the US and I in the EU. We never had any problem with datetime.

That would be crazy because in datetime there is not in a special culture.
It is a "long" which holds a counter of 100 nanoseconds ticks that started
(in Net) at the Christian calendar date 01/01/01 00:00:00. In other systems the starting time and way it is done can be different.

But never try to convert the datetime to string formats with another reasons than to show those.

I hope this helps,

Cor
"andreas" <an*****@pandora.be> schreef in bericht
news:Od**********************@phobos.telenet-ops.be...
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors.
How can I change for a while in the project the date format in vb.code ( not in Windows) and how can I find out which date format the PC Windows is using.
Thanks for any response


Jun 15 '06 #5

P: n/a
"andreas" <an*****@pandora.be> schrieb:
When I copy a vb.net project using date formats from one PC with a windows
date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I
get errors.
How can I change for a while in the project the date format in vb.code (
not in Windows) and how can I find out which date format the PC Windows is
using.


'System.Globalization.CultureInfo.CurrentCulture.D ateTimeFormat'.

Using a culture-specific date/time format to persist dates is never a good
idea if data is exchanged between machines which are potentially running
with different date/time formats. Instead, use
'CultureInfo.InvariantCulture.DateTimeFormat' to format the dates when
persisting them and use the invariant culture to read the date values later
on.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 15 '06 #6

P: n/a
Herfried,

The invarianculture in case of datetime is associated with the English
Language where you can have dependend of the culture june 15 and 15 june.

This makes it possible to do a dataparse.time(date in written words) for
both culture systems in the English language.

Dates written in German needs the parameter in that case that it is in the
German culture, however if that is the local setting than Nothing is more
than enough (while invariantculture will than have the same effect as
nothing because the culture is already German). The last is probably your
situation.

The system does not automaticly recognise that by instance "1/12/2006" is
one time 12 december and anoter time januari 12 how much time you write
that it is an invariant culture.

Cor

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
"andreas" <an*****@pandora.be> schrieb:
When I copy a vb.net project using date formats from one PC with a
windows
date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I
get errors.
How can I change for a while in the project the date format in vb.code (
not in Windows) and how can I find out which date format the PC Windows
is
using.


'System.Globalization.CultureInfo.CurrentCulture.D ateTimeFormat'.

Using a culture-specific date/time format to persist dates is never a good
idea if data is exchanged between machines which are potentially running
with different date/time formats. Instead, use
'CultureInfo.InvariantCulture.DateTimeFormat' to format the dates when
persisting them and use the invariant culture to read the date values
later on.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 15 '06 #7

P: n/a
Andreas,

Did you set a string to a datetime somewhere?

By instance a command like
dim a as date = CDate(25/06/2006)"
or the same with
DateTime.parse
or with
DateTime.Convert
or with
CType("date",datetime)

Cor

"andreas" <an*****@pandora.be> schreef in bericht
news:uF***********************@phobos.telenet-ops.be...
When the date format is changed in windows (configuration panel) i got a
error on a different PC and on my own PC the dates with month = 25,13,..
and so on where not listened.
It depens likely on the settings mm/dd/yyyy or yyy/mm/dd.
And that is my question for a solution in vb.net to detect and to change
these PC settings
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oe**************@TK2MSFTNGP03.phx.gbl...
Andreas,

Strange, I can assure you that Ken and I exhange programs on regular
base.

He is in the US and I in the EU. We never had any problem with datetime.

That would be crazy because in datetime there is not in a special
culture.
It is a "long" which holds a counter of 100 nanoseconds ticks that
started
(in Net) at the Christian calendar date 01/01/01 00:00:00. In other

systems
the starting time and way it is done can be different.

But never try to convert the datetime to string formats with another

reasons
than to show those.

I hope this helps,

Cor
"andreas" <an*****@pandora.be> schreef in bericht
news:Od**********************@phobos.telenet-ops.be...
> When I copy a vb.net project using date formats from one PC with a windows > date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I > get errors.
> How can I change for a while in the project the date format in vb.code ( > not in Windows) and how can I find out which date format the PC Windows is > using.
> Thanks for any response
>
>
>



Jun 15 '06 #8

P: n/a
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
The invarianculture in case of datetime is associated with the English
Language where you can have dependend of the culture june 15 and 15 june.
The invariant culture is invariant by definition and it's unique, which
means that it doesn't suffer from the problems other cultures suffer from.
If June, 15th is persisted using the invariant culture and later read using
the invariant culture, it will always result in June, 15th.
This makes it possible to do a dataparse.time(date in written words) for
both culture systems in the English language.
Why would you want to mix up different cultures?
'CultureInfo.InvariantCulture' has (by definition) as much to do with 'de'
as with 'en'. It's simply a separate culture.
Dates written in German needs the parameter in that case that it is in the
German culture, however if that is the local setting than Nothing is more
than enough (while invariantculture will than have the same effect as
nothing because the culture is already German).
?!? 'InvariantCulture' is a completely independent culture. It has the
same semantics on all systems and thus will never be the same as another
culture.
The system does not automaticly recognise that by instance "1/12/2006" is
one time 12 december and anoter time januari 12 how much time you write
that it is an invariant culture.


If you have a 'Date' variable representing '#1/12/2006#' (written as VB date
literal) and persist it using the invariant culture and later use the
invariant culture to read the persisted value the resulting 'Date' object
will have the value '#1/12/2006#'. One doesn't have to care about and know
the format used to persist the date using the invariant culture. The
invariant culture's main purpose is to make exchange of data between
different systems running with different culture settings easier by removing
any ambiguities potentially caused by different culture settings.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 15 '06 #9

P: n/a
Herfried,

What does this text in the description page of DateTime mean for you.

Each DateTime member implicitly uses the Gregorian calendar to perform its
operation, with the exception of constructors that specify a calendar and
methods that implicitly specify a calendar with a parameter derived from
IFormatProvider, such as System.Globalization.DateTimeFormatInfo. Use the
System.Globalization.Calendar class to perform date and time operations with
a different calendar.
*methods* that implicitly specify a calendar etc.

The description from the datetime is:
The DateTime value type represents dates and times with values ranging from
12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) to 11:59:59
P.M., December 31, 9999 A.D. (C.E.)

Time values are measured in 100-nanosecond units called ticks, and a
particular date is the number of ticks since 12:00 midnight, January 1, 1
A.D. (C.E.) in the GregorianCalendar calendar. For example, a ticks value of
31241376000000000L represents the date, Friday, January 01, 0100 12:00:00
midnight. A DateTime value is always expressed in the context of an explicit
or default calendar.

As I read it as you write, than you give me the idea that for you a datetime
is stored in the way as in the literals. The dateobject does not have the
value '#1/12/2006#' it has just a counter which has a starting point at
01/01/00 00:00:00 in our notation in ISO.

I could not find any member for a stored DateTimeFormatInfo inside the
DateTime structure

Cor

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schreef in bericht
news:e2**************@TK2MSFTNGP05.phx.gbl...
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
The invarianculture in case of datetime is associated with the English
Language where you can have dependend of the culture june 15 and 15 june.


The invariant culture is invariant by definition and it's unique, which
means that it doesn't suffer from the problems other cultures suffer from.
If June, 15th is persisted using the invariant culture and later read
using the invariant culture, it will always result in June, 15th.
This makes it possible to do a dataparse.time(date in written words) for
both culture systems in the English language.


Why would you want to mix up different cultures?
'CultureInfo.InvariantCulture' has (by definition) as much to do with 'de'
as with 'en'. It's simply a separate culture.
Dates written in German needs the parameter in that case that it is in
the German culture, however if that is the local setting than Nothing is
more than enough (while invariantculture will than have the same effect
as nothing because the culture is already German).


?!? 'InvariantCulture' is a completely independent culture. It has the
same semantics on all systems and thus will never be the same as another
culture.
The system does not automaticly recognise that by instance "1/12/2006" is
one time 12 december and anoter time januari 12 how much time you write
that it is an invariant culture.


If you have a 'Date' variable representing '#1/12/2006#' (written as VB
date literal) and persist it using the invariant culture and later use the
invariant culture to read the persisted value the resulting 'Date' object
will have the value '#1/12/2006#'. One doesn't have to care about and
know the format used to persist the date using the invariant culture. The
invariant culture's main purpose is to make exchange of data between
different systems running with different culture settings easier by
removing any ambiguities potentially caused by different culture settings.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 15 '06 #10

P: n/a
Yes
I have to read a textdate from a textfile into a textbox and I would'n
change my textfile.
I put it again, I like to change the windows date format with a command in
my vb.net program so that I can run my program on any PC.
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eq**************@TK2MSFTNGP05.phx.gbl...
Andreas,

Did you set a string to a datetime somewhere?

By instance a command like
dim a as date = CDate(25/06/2006)"
or the same with
DateTime.parse
or with
DateTime.Convert
or with
CType("date",datetime)

Cor

"andreas" <an*****@pandora.be> schreef in bericht
news:uF***********************@phobos.telenet-ops.be...
When the date format is changed in windows (configuration panel) i got a
error on a different PC and on my own PC the dates with month = 25,13,..
and so on where not listened.
It depens likely on the settings mm/dd/yyyy or yyy/mm/dd.
And that is my question for a solution in vb.net to detect and to change
these PC settings
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oe**************@TK2MSFTNGP03.phx.gbl...
Andreas,

Strange, I can assure you that Ken and I exhange programs on regular
base.

He is in the US and I in the EU. We never had any problem with datetime.
That would be crazy because in datetime there is not in a special
culture.
It is a "long" which holds a counter of 100 nanoseconds ticks that
started
(in Net) at the Christian calendar date 01/01/01 00:00:00. In other

systems
the starting time and way it is done can be different.

But never try to convert the datetime to string formats with another

reasons
than to show those.

I hope this helps,

Cor
"andreas" <an*****@pandora.be> schreef in bericht
news:Od**********************@phobos.telenet-ops.be...
> When I copy a vb.net project using date formats from one PC with a

windows
> date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd
then I
> get errors.
> How can I change for a while in the project the date format in
vb.code (
> not in Windows) and how can I find out which date format the PC
Windows is
> using.
> Thanks for any response
>
>
>



Jun 15 '06 #11

P: n/a
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
I could not find any member for a stored DateTimeFormatInfo inside the
DateTime structure


Nobody's claiming that. 'DateTime' per-se doesn't have to do anything with
a specific culture. Cultures come into the play when formatting the date to
persist it, for example.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 15 '06 #12

P: n/a
Andreas,

Than you have to know the format how that date is written and use the
overloaded command.

datetime.parseexact

http://msdn.microsoft.com/library/de...xacttopic1.asp

If you are sure that the dates are only in numbers than the last operand can
be nothing.

Be aware that this is only in the case of by instand textfiles to datetime.

In another culture will the user in the UI type the date in the style he is
used to, therefore from a textbox a CDate works perfect.

I hope this hels,

Cor
"andreas" <an*****@pandora.be> schreef in bericht
news:Vl***********************@phobos.telenet-ops.be...
Yes
I have to read a textdate from a textfile into a textbox and I would'n
change my textfile.
I put it again, I like to change the windows date format with a command in
my vb.net program so that I can run my program on any PC.
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eq**************@TK2MSFTNGP05.phx.gbl...
Andreas,

Did you set a string to a datetime somewhere?

By instance a command like
dim a as date = CDate(25/06/2006)"
or the same with
DateTime.parse
or with
DateTime.Convert
or with
CType("date",datetime)

Cor

"andreas" <an*****@pandora.be> schreef in bericht
news:uF***********************@phobos.telenet-ops.be...
> When the date format is changed in windows (configuration panel) i got
> a
> error on a different PC and on my own PC the dates with month =
> 25,13,..
> and so on where not listened.
> It depens likely on the settings mm/dd/yyyy or yyy/mm/dd.
> And that is my question for a solution in vb.net to detect and to
> change
> these PC settings
>
>
> "Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
> news:Oe**************@TK2MSFTNGP03.phx.gbl...
>> Andreas,
>>
>> Strange, I can assure you that Ken and I exhange programs on regular
>> base.
>>
>> He is in the US and I in the EU. We never had any problem with datetime. >>
>> That would be crazy because in datetime there is not in a special
>> culture.
>> It is a "long" which holds a counter of 100 nanoseconds ticks that
>> started
>> (in Net) at the Christian calendar date 01/01/01 00:00:00. In other
> systems
>> the starting time and way it is done can be different.
>>
>> But never try to convert the datetime to string formats with another
> reasons
>> than to show those.
>>
>> I hope this helps,
>>
>> Cor
>>
>>
>> "andreas" <an*****@pandora.be> schreef in bericht
>> news:Od**********************@phobos.telenet-ops.be...
>> > When I copy a vb.net project using date formats from one PC with a
> windows
>> > date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then > I
>> > get errors.
>> > How can I change for a while in the project the date format in vb.code > (
>> > not in Windows) and how can I find out which date format the PC Windows > is
>> > using.
>> > Thanks for any response
>> >
>> >
>> >
>>
>>
>
>



Jun 16 '06 #13

P: n/a
Herfried and Cor,
Thanks, it is very interesting but I want ( if possible) a direct answer.

When can change in Windows - Control panel the format of the date and it is
important for vb.net when reading a date in plain tekst in a textfile
When the windows format is f.e. yyyy/mm/dd and the textfile gives in plain
tekst 31/12/2005 then I get a error.
When I change the windows format in dd/mm/yyyy than the date is reading.
Is it possible and how can I :
Dedect in VB.net what the setting is in O.S.
Change this setting in what I want in vb.net at the beginning of the
program.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:#r**************@TK2MSFTNGP05.phx.gbl...
"andreas" <an*****@pandora.be> schrieb:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors.
How can I change for a while in the project the date format in vb.code ( not in Windows) and how can I find out which date format the PC Windows is using.
'System.Globalization.CultureInfo.CurrentCulture.D ateTimeFormat'.

Using a culture-specific date/time format to persist dates is never a good
idea if data is exchanged between machines which are potentially running
with different date/time formats. Instead, use
'CultureInfo.InvariantCulture.DateTimeFormat' to format the dates when
persisting them and use the invariant culture to read the date values

later on.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 16 '06 #14

P: n/a
Andreas,

Newsgroups are meant as a communitiy, where problems can be discussed in any
way by the contributers who want to learn from each other.

If you want only a direct answer to your questions, than you can better go
to a paid Microsoft Support Center or hire in another way an advisor.

Just my thought,

Cor

"andreas" <an*****@pandora.be> schreef in bericht
news:0S***********************@phobos.telenet-ops.be...
Herfried and Cor,
Thanks, it is very interesting but I want ( if possible) a direct answer.

When can change in Windows - Control panel the format of the date and it
is
important for vb.net when reading a date in plain tekst in a textfile
When the windows format is f.e. yyyy/mm/dd and the textfile gives in plain
tekst 31/12/2005 then I get a error.
When I change the windows format in dd/mm/yyyy than the date is reading.
Is it possible and how can I :
Dedect in VB.net what the setting is in O.S.
Change this setting in what I want in vb.net at the beginning of the
program.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:#r**************@TK2MSFTNGP05.phx.gbl...
"andreas" <an*****@pandora.be> schrieb:
> When I copy a vb.net project using date formats from one PC with a windows > date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I > get errors.
> How can I change for a while in the project the date format in vb.code ( > not in Windows) and how can I find out which date format the PC Windows is > using.


'System.Globalization.CultureInfo.CurrentCulture.D ateTimeFormat'.

Using a culture-specific date/time format to persist dates is never a
good
idea if data is exchanged between machines which are potentially running
with different date/time formats. Instead, use
'CultureInfo.InvariantCulture.DateTimeFormat' to format the dates when
persisting them and use the invariant culture to read the date values

later
on.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Jun 16 '06 #15

P: n/a
Hi, Andreas:

To retrieve the date format for the current user use this:
Dim tdfi As New System.Globalization.DateTimeFormatInfo
Dim dtFormat As String = tdfi.CurrentInfo.ShortDatePattern

dtFormat then contains the string you're looking for
(e.g. "dd.MM.yyyy"). This is the format of the user settings for the
account the program is running under. So this might only help you to
write the format into a file, but not to recognize the format in the file.

But I wonder, if you receive the file with those data, don't you know
the date format? If not, you might want to ask the person who sends you
the file to include an .INI file with the date format or to write the
date format into the first line of the file. If you know the date format
you can process it like this:

Dim FlatFileDate As String, DisplayDate As String
Dim tMonth As Integer, tDay As Integer, tYear As Integer

FlatFileDate = "06252006" '=MMDDYYYY, that's what you read from your
' file

'Lets say you want to convert to YYYYMMDD

tMonth = Val(Strings.Left(FlatFileDate, 2))
tDay = Val(Strings.Mid(FlatFileDate, 3, 2))
tYear = Val(Strings.Right(FlatFileDate, 4))

Dim dt As New Date(tYear, tMonth, tDay) 'Creates a date variable with
'the date you just processed.

DisplayDate = Format(dt, "Short Date") 'Formats the date to local short
'date

MsgBox(DisplayDate)

Best Regards,

HKSHK

andreas wrote:
When I copy a vb.net project using date formats from one PC with a windows
date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I
get errors.
How can I change for a while in the project the date format in vb.code (
not in Windows) and how can I find out which date format the PC Windows is
using.
Thanks for any response

Jun 16 '06 #16

P: n/a
"andreas" <an*****@pandora.be> schrieb:
When can change in Windows - Control panel the format of the date and it
is
important for vb.net when reading a date in plain tekst in a textfile
When the windows format is f.e. yyyy/mm/dd and the textfile gives in plain
tekst 31/12/2005 then I get a error.
When I change the windows format in dd/mm/yyyy than the date is reading.
Is it possible and how can I :
Dedect in VB.net what the setting is in O.S.


You don't need to worry about the OS settings. Just set the application's
'CurrentCulture' to the culture you want to use to persist the data and then
reset it to its previous value.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 16 '06 #17

P: n/a
Cor,
There is a misunderstanding.
I don't need a personal message but in the newsgroup codelines who are a
solution for my questions.
I see now a answer from herfried which I will try (if I can)

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eA**************@TK2MSFTNGP03.phx.gbl...
Andreas,

Newsgroups are meant as a communitiy, where problems can be discussed in any way by the contributers who want to learn from each other.

If you want only a direct answer to your questions, than you can better go to a paid Microsoft Support Center or hire in another way an advisor.

Just my thought,

Cor

"andreas" <an*****@pandora.be> schreef in bericht
news:0S***********************@phobos.telenet-ops.be...
Herfried and Cor,
Thanks, it is very interesting but I want ( if possible) a direct answer.
When can change in Windows - Control panel the format of the date and it
is
important for vb.net when reading a date in plain tekst in a textfile
When the windows format is f.e. yyyy/mm/dd and the textfile gives in plain tekst 31/12/2005 then I get a error.
When I change the windows format in dd/mm/yyyy than the date is reading.
Is it possible and how can I :
Dedect in VB.net what the setting is in O.S.
Change this setting in what I want in vb.net at the beginning of the
program.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:#r**************@TK2MSFTNGP05.phx.gbl...
"andreas" <an*****@pandora.be> schrieb:
> When I copy a vb.net project using date formats from one PC with a

windows
> date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then
I
> get errors.
> How can I change for a while in the project the date format in
vb.code (
> not in Windows) and how can I find out which date format the PC
Windows is
> using.

'System.Globalization.CultureInfo.CurrentCulture.D ateTimeFormat'.

Using a culture-specific date/time format to persist dates is never a
good
idea if data is exchanged between machines which are potentially

running with different date/time formats. Instead, use
'CultureInfo.InvariantCulture.DateTimeFormat' to format the dates when
persisting them and use the invariant culture to read the date values

later
on.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>



Jun 16 '06 #18

P: n/a
Herfried,
Thanks and I will try your solution.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:#i**************@TK2MSFTNGP05.phx.gbl...
"andreas" <an*****@pandora.be> schrieb:
When can change in Windows - Control panel the format of the date and it
is
important for vb.net when reading a date in plain tekst in a textfile
When the windows format is f.e. yyyy/mm/dd and the textfile gives in plain tekst 31/12/2005 then I get a error.
When I change the windows format in dd/mm/yyyy than the date is reading.
Is it possible and how can I :
Dedect in VB.net what the setting is in O.S.
You don't need to worry about the OS settings. Just set the application's
'CurrentCulture' to the culture you want to use to persist the data and

then reset it to its previous value.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 16 '06 #19

P: n/a
Thanks very much HKSHK ! (and all the others to)
This is the best answer I recieved to my questions!
Thanks a lot again
"HKSHK" <hk***@gmx.net> wrote in message
news:e6**********@news.datemas.de...
Hi, Andreas:

To retrieve the date format for the current user use this:
Dim tdfi As New System.Globalization.DateTimeFormatInfo
Dim dtFormat As String = tdfi.CurrentInfo.ShortDatePattern

dtFormat then contains the string you're looking for
(e.g. "dd.MM.yyyy"). This is the format of the user settings for the
account the program is running under. So this might only help you to
write the format into a file, but not to recognize the format in the file.

But I wonder, if you receive the file with those data, don't you know
the date format? If not, you might want to ask the person who sends you
the file to include an .INI file with the date format or to write the
date format into the first line of the file. If you know the date format
you can process it like this:

Dim FlatFileDate As String, DisplayDate As String
Dim tMonth As Integer, tDay As Integer, tYear As Integer

FlatFileDate = "06252006" '=MMDDYYYY, that's what you read from your
' file

'Lets say you want to convert to YYYYMMDD

tMonth = Val(Strings.Left(FlatFileDate, 2))
tDay = Val(Strings.Mid(FlatFileDate, 3, 2))
tYear = Val(Strings.Right(FlatFileDate, 4))

Dim dt As New Date(tYear, tMonth, tDay) 'Creates a date variable with
'the date you just processed.

DisplayDate = Format(dt, "Short Date") 'Formats the date to local short
'date

MsgBox(DisplayDate)

Best Regards,

HKSHK

andreas wrote:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors.
How can I change for a while in the project the date format in vb.code ( not in Windows) and how can I find out which date format the PC Windows is using.
Thanks for any response

Jun 16 '06 #20

P: n/a
Andreas,

I would just use the parseexact as I have showed you in another message and
if you speak Dutch than you can try to get the Benelux Dutch language .Net
magazine from march. I have written a complete article about more than your
question alone in that about all kind of situations with DateTime (for C#
and VBNet).

Cor

"andreas" <an*****@pandora.be> schreef in bericht
news:FM***********************@phobos.telenet-ops.be...
Cor,
There is a misunderstanding.
I don't need a personal message but in the newsgroup codelines who are a
solution for my questions.
I see now a answer from herfried which I will try (if I can)

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eA**************@TK2MSFTNGP03.phx.gbl...
Andreas,

Newsgroups are meant as a communitiy, where problems can be discussed in

any
way by the contributers who want to learn from each other.

If you want only a direct answer to your questions, than you can better

go
to a paid Microsoft Support Center or hire in another way an advisor.

Just my thought,

Cor

"andreas" <an*****@pandora.be> schreef in bericht
news:0S***********************@phobos.telenet-ops.be...
> Herfried and Cor,
> Thanks, it is very interesting but I want ( if possible) a direct answer. >
> When can change in Windows - Control panel the format of the date and
> it
> is
> important for vb.net when reading a date in plain tekst in a textfile
> When the windows format is f.e. yyyy/mm/dd and the textfile gives in plain > tekst 31/12/2005 then I get a error.
> When I change the windows format in dd/mm/yyyy than the date is
> reading.
> Is it possible and how can I :
> Dedect in VB.net what the setting is in O.S.
> Change this setting in what I want in vb.net at the beginning of the
> program.
>
>
> "Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
> news:#r**************@TK2MSFTNGP05.phx.gbl...
>> "andreas" <an*****@pandora.be> schrieb:
>> > When I copy a vb.net project using date formats from one PC with a
> windows
>> > date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then > I
>> > get errors.
>> > How can I change for a while in the project the date format in vb.code > (
>> > not in Windows) and how can I find out which date format the PC Windows > is
>> > using.
>>
>> 'System.Globalization.CultureInfo.CurrentCulture.D ateTimeFormat'.
>>
>> Using a culture-specific date/time format to persist dates is never a
>> good
>> idea if data is exchanged between machines which are potentially running >> with different date/time formats. Instead, use
>> 'CultureInfo.InvariantCulture.DateTimeFormat' to format the dates when
>> persisting them and use the invariant culture to read the date values
> later
>> on.
>>
>> --
>> M S Herfried K. Wagner
>> M V P <URL:http://dotnet.mvps.org/>
>> V B <URL:http://classicvb.org/petition/>
>>
>
>



Jun 16 '06 #21

This discussion thread is closed

Replies have been disabled for this discussion.