473,385 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

changing the date format in vb.net

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
20 35346
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
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
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
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
"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
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
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
"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
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
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
"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
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
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
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
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
"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Shaiboy_UK | last post by:
Hi All, Sorry if this is the wrong newsgroup to post into, on this topic, if so, please point me in the right direction..... Currently working on a ASP for a friend, which requires the date...
8
by: Rob | last post by:
Hi all, Is it possible to change the Session.LCID in a hyperlink? My problem is I'm calling a Date from a database to use as a querystring in the hyperlink but I also need to display the date as...
6
by: Suzanne | last post by:
Hi, I am having problems with my website which uses ASP. It is switching between American and European date formats - this is causing problems on the page which use the Date function. Most of...
1
by: jt | last post by:
I posted this yesterday, but I am not seeing this out yet: I am having problems with updating a date field in a certain format. The data is stored in an Oracle database. The date is...
2
by: Chris | last post by:
Hello, i'm using a form with 2 dates in the format mm/dd/yyyy in it. I wanna calculate the days between the two dates. I tried it like this: <script language="JavaScript"> var date1 = new...
2
by: bh | last post by:
Changing a Date Time Value I have a form with a date time picker or it and a button. When the button is pressed it passes the date/time into a stored procedure that queries an SQL database. ...
0
by: Kyote | last post by:
In my project I have an underlying Access DB. One of the column's is currently set as a text field but I need to change it to a date/time field. I can open the Access DB in MS Access and change...
5
mgpsivan
by: mgpsivan | last post by:
Hi, i have form in Asp.net(2003) in that i've to change the format of the date by the following statement Format(Date.Today, "dd/mm/yyyy") but when i give this code the month part displays as...
0
by: Just4U | last post by:
Hello, My config : Windows 2003 x64 (US VERSION) + sp2, IIS 6 All regional settings to French (even for default user) In my ASP pages dates are in the good format (french:dd/mm/yyyy), but...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.