473,397 Members | 1,949 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,397 software developers and data experts.

date from different countries

I have an applicatoin that works 100% perfect when running on a machine
setup for English (United States), but when I change it to Spanish
(Mexico), the dates start giving me fits.

THe reason is USA is mm/dd/yyyy and mexico is dd/mm/yyyy. So, with the
computer set to mexico, any standard CDATE function is going to return
the date in the dd/mm/yyyy setting since that is what the computer is
set to.

I want to be able to enter a date in dd/mm/yyyy format but return a true
date, but in the format mm/dd/yyyy, similar to CDate. I don't want a
string, I want a real date.

I wrote a routine that changed the order to get it in the format, but it
is a string. When I then try to change it to a date, the Cdate routine
either changes the format or errors because it is trying to change the
format.

Dim junk As Date
Dim sjunk As String
junk = #1/1/1901#
Try
If Not IsDBNull(in_object) Then
sjunk = DRStr(in_object)
If
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern <>
"M/d/yyyy" Then
' not USA
Dim xpattern As String
xpattern =
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern
If Mid(xpattern, 1, 1) = "d" Then
' day is first
Dim ddate As String
Dim xflds() As String
xflds = Split(DRStr(sjunk), "/")
ddate = xflds(1) & "/" & xflds(0) & "/" & xflds(2)
sjunk = ddate
End If
End If
junk = CDate(sjunk)
Else
junk = CDate(in_object)
End If
Catch oExcept As Exception
'ShowMessage(oExcept.Message)
End Try
Return junk

The statement junk=cdate(sjunk) is what is changing the date back into
the global settings on the comptuer.

Any help would be greatly appreciated. I really wish CDate would allow
me to have an argument as the globalization settings allowing me to
force what setting I want the date to be. Don't forget, the FORMAT
command returns a string, not a date.

Thanks in advance.

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Jan 18 '07 #1
21 3331
Dates in different cultures can be a bit of a minefield.

As long as the year part of the date is entered with 4 digits then that part
is not generally an issue.

The problems arise when you need to analyse what the user has entered for
the day and month parts.

If the day part is 13 or greater then that is easily identifiable as the day
because months are only 1 to 12.

If the day part and the month part are the same then there is no problem
because 01/01/2006 is easily identifiable in either dd/MM/yyyy or MM/dd/yyyy
formats.

If the day part is 1 to 12 and it is not the same as the month part then you
have some issues. E.G. Is 01/02/2007 meant to represent the 1st of February
or the 2nd of January.

If the instruction to the user is to enter the date as dd/MM/yyyy (or
MM/dd/yyyy) regardless of culture then one can use:

Dim _d As DateTime = DateTime.ParseExact(value, "dd/MM/yyyy")
' or MM/dd/yyyy as required

If the instruction to the user is to enter the date as per the culture of
the machine then one can use:

Dim _d As DateTime = DateTime.ParseExact(value,
DateTimeFormatInfo.CurrentInfo.ShortDatePattern)

Unfortunately, any given machine can have it's ShortDatePattern set to a
different pattern than the default pattern for the culture of the machine.

One way of overcoming this issue is to pad the parts of the date string to
make sure the day and month parts are the expected length:

Dim _parts As String() = value.Split("/"c)
_parts(0) = Parts(0).PadLeft(2, "0")
_parts(1) = Parts(1).PadLeft(2, "0")
value = String.Join(".", _parts)

For value = "1/1/2007", value will be modified to "01/01/2007" which will
now work with:

Dim _d As DateTime = DateTime.ParseExact(value, "dd/MM/yyyy")
"Darin" <darin_nospam@nospameverwrote in message
news:ei**************@TK2MSFTNGP04.phx.gbl...
>I have an applicatoin that works 100% perfect when running on a machine
setup for English (United States), but when I change it to Spanish
(Mexico), the dates start giving me fits.

THe reason is USA is mm/dd/yyyy and mexico is dd/mm/yyyy. So, with the
computer set to mexico, any standard CDATE function is going to return
the date in the dd/mm/yyyy setting since that is what the computer is
set to.

I want to be able to enter a date in dd/mm/yyyy format but return a true
date, but in the format mm/dd/yyyy, similar to CDate. I don't want a
string, I want a real date.

I wrote a routine that changed the order to get it in the format, but it
is a string. When I then try to change it to a date, the Cdate routine
either changes the format or errors because it is trying to change the
format.

Dim junk As Date
Dim sjunk As String
junk = #1/1/1901#
Try
If Not IsDBNull(in_object) Then
sjunk = DRStr(in_object)
If
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern <>
"M/d/yyyy" Then
' not USA
Dim xpattern As String
xpattern =
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern
If Mid(xpattern, 1, 1) = "d" Then
' day is first
Dim ddate As String
Dim xflds() As String
xflds = Split(DRStr(sjunk), "/")
ddate = xflds(1) & "/" & xflds(0) & "/" & xflds(2)
sjunk = ddate
End If
End If
junk = CDate(sjunk)
Else
junk = CDate(in_object)
End If
Catch oExcept As Exception
'ShowMessage(oExcept.Message)
End Try
Return junk

The statement junk=cdate(sjunk) is what is changing the date back into
the global settings on the comptuer.

Any help would be greatly appreciated. I really wish CDate would allow
me to have an argument as the globalization settings allowing me to
force what setting I want the date to be. Don't forget, the FORMAT
command returns a string, not a date.

Thanks in advance.

Darin

*** Sent via Developersdex http://www.developersdex.com ***

Jan 18 '07 #2
Just use universal date ISO 8601 formats

YYYYMMDD YYYY-MM-DD

hhmmss hh:mm:ss
this should work on any system regardless of there local settings

regards

Michel

"Darin" <darin_nospam@nospameverschreef in bericht
news:ei**************@TK2MSFTNGP04.phx.gbl...
>I have an applicatoin that works 100% perfect when running on a machine
setup for English (United States), but when I change it to Spanish
(Mexico), the dates start giving me fits.

THe reason is USA is mm/dd/yyyy and mexico is dd/mm/yyyy. So, with the
computer set to mexico, any standard CDATE function is going to return
the date in the dd/mm/yyyy setting since that is what the computer is
set to.

I want to be able to enter a date in dd/mm/yyyy format but return a true
date, but in the format mm/dd/yyyy, similar to CDate. I don't want a
string, I want a real date.

I wrote a routine that changed the order to get it in the format, but it
is a string. When I then try to change it to a date, the Cdate routine
either changes the format or errors because it is trying to change the
format.

Dim junk As Date
Dim sjunk As String
junk = #1/1/1901#
Try
If Not IsDBNull(in_object) Then
sjunk = DRStr(in_object)
If
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern <>
"M/d/yyyy" Then
' not USA
Dim xpattern As String
xpattern =
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern
If Mid(xpattern, 1, 1) = "d" Then
' day is first
Dim ddate As String
Dim xflds() As String
xflds = Split(DRStr(sjunk), "/")
ddate = xflds(1) & "/" & xflds(0) & "/" & xflds(2)
sjunk = ddate
End If
End If
junk = CDate(sjunk)
Else
junk = CDate(in_object)
End If
Catch oExcept As Exception
'ShowMessage(oExcept.Message)
End Try
Return junk

The statement junk=cdate(sjunk) is what is changing the date back into
the global settings on the comptuer.

Any help would be greatly appreciated. I really wish CDate would allow
me to have an argument as the globalization settings allowing me to
force what setting I want the date to be. Don't forget, the FORMAT
command returns a string, not a date.

Thanks in advance.

Darin

*** Sent via Developersdex http://www.developersdex.com ***

Jan 18 '07 #3
Darin,

There is no #1-1-1900# or whatever that is the representation from the
debugger.

DateTimes are forever ticks starting at a not real moment (different for
dotNet and databases), which forever calculate the date and times based on
the culture settings of the user.

I prefer very often the CDate because it does a lot automatic.

Cor

"Darin" <darin_nospam@nospameverschreef in bericht
news:ei**************@TK2MSFTNGP04.phx.gbl...
>I have an applicatoin that works 100% perfect when running on a machine
setup for English (United States), but when I change it to Spanish
(Mexico), the dates start giving me fits.

THe reason is USA is mm/dd/yyyy and mexico is dd/mm/yyyy. So, with the
computer set to mexico, any standard CDATE function is going to return
the date in the dd/mm/yyyy setting since that is what the computer is
set to.

I want to be able to enter a date in dd/mm/yyyy format but return a true
date, but in the format mm/dd/yyyy, similar to CDate. I don't want a
string, I want a real date.

I wrote a routine that changed the order to get it in the format, but it
is a string. When I then try to change it to a date, the Cdate routine
either changes the format or errors because it is trying to change the
format.

Dim junk As Date
Dim sjunk As String
junk = #1/1/1901#
Try
If Not IsDBNull(in_object) Then
sjunk = DRStr(in_object)
If
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern <>
"M/d/yyyy" Then
' not USA
Dim xpattern As String
xpattern =
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern
If Mid(xpattern, 1, 1) = "d" Then
' day is first
Dim ddate As String
Dim xflds() As String
xflds = Split(DRStr(sjunk), "/")
ddate = xflds(1) & "/" & xflds(0) & "/" & xflds(2)
sjunk = ddate
End If
End If
junk = CDate(sjunk)
Else
junk = CDate(in_object)
End If
Catch oExcept As Exception
'ShowMessage(oExcept.Message)
End Try
Return junk

The statement junk=cdate(sjunk) is what is changing the date back into
the global settings on the comptuer.

Any help would be greatly appreciated. I really wish CDate would allow
me to have an argument as the globalization settings allowing me to
force what setting I want the date to be. Don't forget, the FORMAT
command returns a string, not a date.

Thanks in advance.

Darin

*** Sent via Developersdex http://www.developersdex.com ***

Jan 18 '07 #4
Thanks.

I entered in today's date (18/1/2007) and then used:

DateTime.ParseExact(DRStr(in_object), "MM/dd/yyyy",
System.Globalization.DateTimeFormatInfo.CurrentInf o)

and it received an error that the string isn't a valid date (my computer
is set for Spanish(Mexico) so the date is dd/mm/yyyy)

Any ideas.

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Jan 18 '07 #5
Ummmmmm.... yeah!

18/1/2007 is clearly supposed to represent the 18th of January because 18 is
greater than the maximum number for month (12).

DateTime.ParseExact(DRStr(in_object), "MM/dd/yyyy",
System.Globalization.DateTimeFormatInfo.CurrentInf o)

specifies that the result of DRStr(in_object) MUST be in MM/dd/yyyy format.
If it is not in that EXACT format then it will throw an exception (as you
have observed).

18/1/2007 is actually dd/M/yyyy format.

Note that everything I said in my previous post was in context of your
statement that you wouldb entering dates in dd/MM/yyyy format (3rd
paragraph, 1st sentence).

For that you need:

DateTime.ParseExact(DRStr(in_object), "dd/MM/yyyy",
System.Globalization.DateTimeFormatInfo.CurrentInf o)

Note that each placeholder in the format string means a digit, so dd means
01 and not 1 and MM means 01 and not 1. Thus 18/01/2007 matches dd/MM/yyyy
format whereas 18/1/2007 matches dd/m/yy format.
"Darin" <darin_nospam@nospameverwrote in message
news:u$*************@TK2MSFTNGP04.phx.gbl...
Thanks.

I entered in today's date (18/1/2007) and then used:

DateTime.ParseExact(DRStr(in_object), "MM/dd/yyyy",
System.Globalization.DateTimeFormatInfo.CurrentInf o)

and it received an error that the string isn't a valid date (my computer
is set for Spanish(Mexico) so the date is dd/mm/yyyy)

Any ideas.

Darin

*** Sent via Developersdex http://www.developersdex.com ***

Jan 18 '07 #6
But CDate won't work because it puts it in the format the computer is
set to and not the format I want it in.

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Jan 18 '07 #7
I guess I don't understand what the parseexact is to do, and the
documentation wasn't too much of a help. When I did the following with
18/1/2007, I got the last message to be 18/1/2007, which makes it look
like the datetime is putting it back to the global settings.

sjunk = DRStr(in_object)
If System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern
<"M/d/yyyy" Then
' not USA, create a string in USA format
Dim xpattern As String
xpattern =
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern
If Mid(xpattern, 1, 1) = "d" Then 'd/m/y
' day is first
Dim ddate As String
Dim xflds() As String
xflds = Split(DRStr(sjunk), "/")
ddate = xflds(1) & "/" & xflds(0) & "/" & Mid(xflds(2), 1, 4)
'changed to m/d/y
sjunk = ddate
ShowMessage("A-" & sjunk) ' 1/18/2007
End If
End If
Dim format As New System.Globalization.CultureInfo("en-US", True)

ShowMessage("B-" & sjunk) ' 1/18/2007
ShowMessage("C-" & DRStr(DateTime.ParseExact(sjunk, "M/d/yyyy",
format))) ' 18/1/2007
Return DateTime.ParseExact(sjunk, "M/d/yyyy", format)

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Jan 18 '07 #8
Darin,

I get more and more the idea that you want your Dates been showed in a way
that only people from the USA understand.

However there is no problem at all to do that.

Public Class Main
Public Shared Sub Main()
Threading.Thread.CurrentThread.CurrentCulture = _
New Globalization.CultureInfo("en-US")

MessageBox.Show(CDate("01-06-2004 11:59 PM").AddDays(1).ToString)

'And set the culture back when it was not your own culture
Threading.Thread.CurrentThread.CurrentCulture = _
Globalization.CultureInfo.InstalledUICulture
End Sub
End Class

Cor
Jan 18 '07 #9
Ok. I have a routine that accepts a date argument and needs a date
returned, but in true USA format.

public function USADate(in_date as date) As date
dim xout as date
Threading.Thread.CurrentThread.CurrentCulture = _
New Globalization.CultureInfo("en-US")

xout=cdate(in_date)

'And set the culture back when it was not your own culture
Threading.Thread.CurrentThread.CurrentCulture = _
Globalization.CultureInfo.InstalledUICulture

return xout
end function

If I change the culture in the routine, and change it back, then return
a date, what date is it going to be, USA format or Mexico? I just need a
routine that can take any date format and return a date in true US
format so it can write it to the database correctly.

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Jan 18 '07 #10
Take a step back for a moment.

Create a new Windows Forms project, place a button (Button1) on the form and
paste the following code into the
form.

Click the button and observe the results.

Change the initial date string and the 'foreign' culture to different values
and observe the results.

Once you have got a feel for what it is doing, then you can incorporate it
into your application.

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click

Try
Console.WriteLine(GetUSDateString("19/1/2007"))
Catch _ex As Exception
Console.WriteLine(_ex.ToString)
End Try

End Sub

Private Function GetUSDateString(ByVal value As String) As String

' The following is commented out so we can simulate different cultures
'Dim myCI As CultureInfo = New
CultureInfo(CultureInfo.CurrentCulture.Name, False)

' The following line is used to simulate different cultures
' Change the en-NZ to es-MX or the name for any other culture you desire
Dim _myCI As CultureInfo = New CultureInfo("en-NZ", False)

' CultureInfo object for en-US culture
Dim _usCI As CultureInfo = New CultureInfo("en-US", False)

Dim _date As DateTime

Try
' Attempt to parse value using the 'foreign' culture
_date = DateTime.Parse(value, _myCI.DateTimeFormat)
Catch _ex As FormatException
' That didn't work
Try
' so Attempt to parse value using the en_US culture
_date = DateTime.Parse(value, _usCI.DateTimeFormat)
Catch _exx As FormatException
' That didn't work either
Try

' so Attempt to parse value using the en_US culture again after
swapping the first 2 parts of value about
_date = DateTime.Parse(Swap(value,
Convert.ToChar(_usCI.DateTimeFormat.DateSeparator) ), _usCI.DateTimeFormat)
Catch _exxx As Exception
' That still didn;t work so throw the exception up the line
Throw
End Try
Catch _exx As Exception
' Some other exception happened so throw ot up the line
Throw
End Try
Catch _ex As Exception

' Some other exception happened so throw ot up the line
Throw
End Try

' One of the parse attempts succeeded so return the result in the
ShortDatePattern of the en_US culture
Return _date.ToString("d", _usCI.DateTimeFormat)

End Function

Private Function Swap(ByVal value As String, ByVal delimiter As Char) As
String

Dim _ss As String() = value.Split(delimiter)

Dim _s As String = _ss(0)

_ss(0) = _ss(1)

_ss(1) = _s

Return String.Join(delimiter, _ss)

End Function
"Darin" <darin_nospam@nospameverwrote in message
news:uK**************@TK2MSFTNGP04.phx.gbl...
>I guess I don't understand what the parseexact is to do, and the
documentation wasn't too much of a help. When I did the following with
18/1/2007, I got the last message to be 18/1/2007, which makes it look
like the datetime is putting it back to the global settings.

sjunk = DRStr(in_object)
If System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern
<"M/d/yyyy" Then
' not USA, create a string in USA format
Dim xpattern As String
xpattern =
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern
If Mid(xpattern, 1, 1) = "d" Then 'd/m/y
' day is first
Dim ddate As String
Dim xflds() As String
xflds = Split(DRStr(sjunk), "/")
ddate = xflds(1) & "/" & xflds(0) & "/" & Mid(xflds(2), 1, 4)
'changed to m/d/y
sjunk = ddate
ShowMessage("A-" & sjunk) ' 1/18/2007
End If
End If
Dim format As New System.Globalization.CultureInfo("en-US", True)

ShowMessage("B-" & sjunk) ' 1/18/2007
ShowMessage("C-" & DRStr(DateTime.ParseExact(sjunk, "M/d/yyyy",
format))) ' 18/1/2007
Return DateTime.ParseExact(sjunk, "M/d/yyyy", format)

Darin

*** Sent via Developersdex http://www.developersdex.com ***

Jan 19 '07 #11
Darin,

Your database is not set in USA format, it is in ticks from 1000/3
milliseconds starting at januari 1 1873 (for SQL server). It is in every
culture the same.

Cor
Jan 19 '07 #12
Hello Darin,
Ok. I have a routine that accepts a date argument and needs a date
returned, but in true USA format.
I understand that you want to get a date as a string like in traditional
BASIC?

Private Function BASICdate(byval ThisDate As Date) As String
Return (ThisDate.Month & "/" & ThisDate.Day & "/" & ThisDate.Year
End Function

Best regards,

Martin
Jan 21 '07 #13
Sorry, routine was not complete, now it is:

Private Function BASICdate(byval ThisDate As Date) As String
Return Format(ThisDate.Month,"00") & "/" & _
Format(ThisDate.Day,"00") & "/" & _
Cstr(ThisDate.Year)
End Function

Best regards,

Martin

Jan 21 '07 #14
"Martin H." <hk***@gmx.netschrieb
Hello Darin,
Ok. I have a routine that accepts a date argument and needs a date
returned, but in true USA format.

I understand that you want to get a date as a string like in
traditional BASIC?

Private Function BASICdate(byval ThisDate As Date) As String
Return (ThisDate.Month & "/" & ThisDate.Day & "/" & ThisDate.Year
End Function
Why not use ThisDate.ToString instead of writing another function? The
format can be a constant.
Armin

Jan 21 '07 #15
Martin,
As Armin suggests: You can simplify that to:
Private Function BASICdate(byval ThisDate As Date) As String
Return ThisDate.ToString("MM/dd/yyyy")
End Function
Which also ensures that the year will be 4 digits.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"HKSHK" <hk***@gmx.netwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
Sorry, routine was not complete, now it is:

Private Function BASICdate(byval ThisDate As Date) As String
Return Format(ThisDate.Month,"00") & "/" & _
Format(ThisDate.Day,"00") & "/" & _
Cstr(ThisDate.Year)
End Function

Best regards,

Martin
Jan 21 '07 #16

Darin wrote:
Ok. I have a routine that accepts a date argument and needs a date
returned, but in true USA format.

public function USADate(in_date as date) As date
dim xout as date
Threading.Thread.CurrentThread.CurrentCulture = _
New Globalization.CultureInfo("en-US")

xout=cdate(in_date)

'And set the culture back when it was not your own culture
Threading.Thread.CurrentThread.CurrentCulture = _
Globalization.CultureInfo.InstalledUICulture

return xout
end function

If I change the culture in the routine, and change it back, then return
a date, what date is it going to be, USA format or Mexico?
<snip>

Neither. A variable of type Date or DateTime is in a "neutral", binary
format, that has nothing to do with the thread's culture (and I guess
that's what Cor is trying to inform you).

It seems you're mistaking a date value with the date representation.
The date value is binary and, again, has nothing to do with a given
culture. The date representation, on the other side, is a string, and
varies according to the culture being used by the thread, the system's
date format, etc.

HTH.

Regards,

Branco.

Jan 22 '07 #17
Hello Jay,
As Armin suggests: You can simplify that to:
>Private Function BASICdate(byval ThisDate As Date) As String
Return ThisDate.ToString("MM/dd/yyyy")
End Function
No, the simplification won't work, because the OP wrote that he wants to
have the US date. The US date has slashes in it (e.g. 01/31/2007).

However, the format command will replace the slashes with the separators
for your country. In my case (Germany) we use dots. With the simplified
routine I get 01.31.2007. To get the real BASIC date the best option is
to assemble the string as I did before.

Best regards,

Martin
Jan 22 '07 #18
Hello Branco,
Neither. A variable of type Date or DateTime is in a "neutral", binary
format, that has nothing to do with the thread's culture (and I guess
that's what Cor is trying to inform you).

It seems you're mistaking a date value with the date representation.
The date value is binary and, again, has nothing to do with a given
culture. The date representation, on the other side, is a string, and
varies according to the culture being used by the thread, the system's
date format, etc.
Correct and incorrect. You are correct that a date variable contains a
"neutral" binary format. However, you don't know what the OP wants to
accomplish. Perhaps he wants to use the date in an SQL query. In this
case he would have to use a string in US format.

Best regards,

Martin
Jan 22 '07 #19

Martin H. wrote:
<snip>
Correct and incorrect. You are correct that a date variable contains a
"neutral" binary format. However, you don't know what the OP wants to
accomplish. Perhaps he wants to use the date in an SQL query. In this
case he would have to use a string in US format.
<snip>

Notice that I didn't mention anything related to formatting the date, I
suppose others had already given that information. Therefore I don't
see the "incorrect" part of my post.

Regards,

Branco.

Jan 22 '07 #20
Martin,

Just reading what the OP wrote in his first message gives in my idea answer
on what you wrote.
>I want to be able to enter a date in dd/mm/yyyy format but return a true
date, but in the format mm/dd/yyyy, similar to CDate. I don't want a
string, I want a real date.
And more of that where he shows to have the opinion that a "real date is"
#MM-dd-yyyy" as the debugger and the intelisence from VB.Net returns it. If
he would had used C# he could have seen that this is only a VB.Net
debugger/intelisence format.

Cor

"Martin H." <hk***@gmx.netschreef in bericht
news:45*********************@news.freenet.de...
Hello Branco,
>Neither. A variable of type Date or DateTime is in a "neutral", binary
format, that has nothing to do with the thread's culture (and I guess
that's what Cor is trying to inform you).

It seems you're mistaking a date value with the date representation.
The date value is binary and, again, has nothing to do with a given
culture. The date representation, on the other side, is a string, and
varies according to the culture being used by the thread, the system's
date format, etc.

Correct and incorrect. You are correct that a date variable contains a
"neutral" binary format. However, you don't know what the OP wants to
accomplish. Perhaps he wants to use the date in an SQL query. In this case
he would have to use a string in US format.

Best regards,

Martin

Jan 23 '07 #21
Martin,
No, the simplification won't work, because the OP wrote that he wants to
have the US date. The US date has slashes in it (e.g. 01/31/2007).
I missed the US date specifically , I only saw m/d/y format.
However, the format command will replace the slashes with the separators
for your country. In my case (Germany) we use dots. With the simplified
Good point, in that case I would include the / literally and not as the date
separator:

Private Function BASICdate(byval ThisDate As Date) As String
Return ThisDate.ToString("MM\/dd\/yyyy")
End Function

http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx

To get the real BASIC date the best option is to assemble the string as I
did before.
I tend to feel its safer to let a type itself handle its own formatting
rather the presume I know how to format it.

IMHO Letting DateTime format itself *is* the only option! Especially when
DateTime custom formatting fully supports it!

BTW: Thank you for identifing a potential "gotcha" in custom formatting!

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Martin H." <hk***@gmx.netwrote in message
news:45*********************@news.freenet.de...
Hello Jay,
>As Armin suggests: You can simplify that to:
>>Private Function BASICdate(byval ThisDate As Date) As String
Return ThisDate.ToString("MM/dd/yyyy")
End Function

No, the simplification won't work, because the OP wrote that he wants to
have the US date. The US date has slashes in it (e.g. 01/31/2007).

However, the format command will replace the slashes with the separators
for your country. In my case (Germany) we use dots. With the simplified
routine I get 01.31.2007. To get the real BASIC date the best option is to
assemble the string as I did before.

Best regards,

Martin
Jan 23 '07 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Dwalker | last post by:
I just want to enter today's date in a text input box with the format mm/dd/yyyy when it receives focus. I've been playing around with this but just can't seem to get it to work. Any help would...
7
by: Marc Pelletier | last post by:
Hello, I have a table with a Day field, defined as smalldatetime. I am filling it from a CSharp application with the following code: DataRow r = dtStaDays.NewRow(); r= station_ID; r =...
5
by: C. Smith | last post by:
I am a web developer building html data entry forms that have a lot of date input fields (month, date, year) on them. I'd like to have a "popup" calendar that allows the user to pick the date using a...
3
by: MattB | last post by:
I've hit a snag with an application I wrote because of the differing date formats in different countries. It's a set of pages that make calls to a COM object that I have wrapped in a web...
10
by: okaminer | last post by:
Hi I have a program which need to get the date in the format of dd/MM/yyyy (example 24/7/2005) but when I use DateTime.Now().ToShortDatetime() the date come back as MM/dd/yyyy (example...
1
by: joeyej | last post by:
I'm using this code to make sure users are unable to choose a date from a drop list (<option value="June 8, 2006, (Thursday), 9am">June 12, 2006, (Thursday), 9am) that is less than two days out...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
6
by: vdicarlo | last post by:
I am a programming amateur and a Python newbie who needs to convert about 100,000,000 strings of the form "1999-12-30" into ordinal dates for sorting, comparison, and calculations. Though my script...
7
by: axapta | last post by:
Hi I need the input of a text field to be as dd/mm/yyyy how can I achieve this? Regards
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.