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

Q: Date to String

Hi

I've just found something very strange when using Date types within string.
Consider the following:

Dim myDate = DateValueRow("The Date")

' myDate is a date taken from a DataTable
' During debugging in a watch window it had value 5/28/03

Dim newStringDate = "The Date is " + myDate

' The value of newStringDate is now 28/05/03 i.e. the month and day have
swapped.

Can anybody explain why this is happening and how to avoid it?

Thanks in advance

Geoff
Nov 20 '05 #1
7 1591
I am guessing that you have your PC set to a different date format then
american? Perhaps the debugger is not recognizing that, but the ToString
method of the datetime class does.

Also, you should turn option strict on, which will force all your variables
to have types, and not allow you to just add together variables of different
types.

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi

I've just found something very strange when using Date types within string. Consider the following:

Dim myDate = DateValueRow("The Date")

' myDate is a date taken from a DataTable
' During debugging in a watch window it had value 5/28/03

Dim newStringDate = "The Date is " + myDate

' The value of newStringDate is now 28/05/03 i.e. the month and day have
swapped.

Can anybody explain why this is happening and how to avoid it?

Thanks in advance

Geoff

Nov 20 '05 #2
Hi Marina,

For your information.
I am guessing that you have your PC set to a different date format then
american? Perhaps the debugger is not recognizing that, but the ToString
method of the datetime class does.


The English VS.studio gives USA formatted dates in the debugger independent
from the region settings. (I do not know what the other language ones do
maybe Herfried can tell).

Cor
..


Nov 20 '05 #3
* "Geoff Jones" <ge***@NODAMNSPAM.com> scripsit:
I've just found something very strange when using Date types within string.
Consider the following:

Dim myDate = DateValueRow("The Date")

' myDate is a date taken from a DataTable
' During debugging in a watch window it had value 5/28/03

Dim newStringDate = "The Date is " + myDate

' The value of newStringDate is now 28/05/03 i.e. the month and day have
swapped.

Can anybody explain why this is happening and how to avoid it?


Inside the IDE, the tooltips and auto window will always show the date
in US date/time format. In your code, 'myDate' is implycitly converted
to a string by concatenating it to a string. This conversion will be
done according to your system's date/time format settings.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
Hi Herfried,

Did you use the German VS version for this, I was curious about that?

Cor
* "Geoff Jones" <ge***@NODAMNSPAM.com> scripsit:
I've just found something very strange when using Date types within string. Consider the following:

Dim myDate = DateValueRow("The Date")

' myDate is a date taken from a DataTable
' During debugging in a watch window it had value 5/28/03

Dim newStringDate = "The Date is " + myDate

' The value of newStringDate is now 28/05/03 i.e. the month and day have
swapped.

Can anybody explain why this is happening and how to avoid it?


Inside the IDE, the tooltips and auto window will always show the date
in US date/time format. In your code, 'myDate' is implycitly converted
to a string by concatenating it to a string. This conversion will be
done according to your system's date/time format settings.

--

Nov 20 '05 #5
SA
All:

What can also be the case (because we don't know which type of app the user
is debugging) is that somehow the Culture for the thread was set to a
European culture.

This could very well be the case in a .NET app, where someone else might
have written that code in the global.asax and Geoff isn't aware of that.

--

Sven
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi

I've just found something very strange when using Date types within string. Consider the following:

Dim myDate = DateValueRow("The Date")

' myDate is a date taken from a DataTable
' During debugging in a watch window it had value 5/28/03

Dim newStringDate = "The Date is " + myDate

' The value of newStringDate is now 28/05/03 i.e. the month and day have
swapped.

Can anybody explain why this is happening and how to avoid it?

Thanks in advance

Geoff

Nov 20 '05 #6
Hi Marina

I switched on Strict as you suggested. I have also worked out a solution to
my problem; although I still don't understand exactly what is going on. By
the way, I had to change the date because otherwise I was getting an
exception that the date was not in the correct format.

Here is my new code:

Dim myDate As DateTime = CDate(DateValueRow("The Date"))

Dim newStringDate As String = "The Date is " + Format(myDate, "MM/dd/yy")

If I don't use Format, and use

Dim newStringDate As String = "The Date is " + myDate.ToString()

I still get the error message that the date is in the wrong format i.e.
inspection of the dates, even by Writeline, shows that the day and month
numbers are swapped in the two different codes.

Any further help would be most appreciated.

Geoff

"Marina" <so*****@nospam.com> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
I am guessing that you have your PC set to a different date format then
american? Perhaps the debugger is not recognizing that, but the ToString
method of the datetime class does.

Also, you should turn option strict on, which will force all your variables to have types, and not allow you to just add together variables of different types.

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40***********************@news.dial.pipex.com ...
Hi

I've just found something very strange when using Date types within

string.
Consider the following:

Dim myDate = DateValueRow("The Date")

' myDate is a date taken from a DataTable
' During debugging in a watch window it had value 5/28/03

Dim newStringDate = "The Date is " + myDate

' The value of newStringDate is now 28/05/03 i.e. the month and day have
swapped.

Can anybody explain why this is happening and how to avoid it?

Thanks in advance

Geoff


Nov 20 '05 #7
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Did you use the German VS version for this, I was curious about that?


Yes.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8

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

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
4
by: Robert Scarborough | last post by:
I have a Table in a Typed Dataset which contains a Date field called EventDate. I've ensured that the field is defined as Date as opposed to DateTime in the Typed Dataset. When I generate an...
15
by: Paul J. Ettl | last post by:
Two questions: I use var date1 = new Date(); to get todays date. But how can I get yesterdays date? Furthermore I use
12
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
2
by: Keith | last post by:
Good Afternoon, New to .Net. I am trying to pass date/time values to a MS Access query depending on what value is selected from a dropdown list box (January, February, etc). I have declared...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
21
by: Darin | last post by:
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...
7
by: creative1 | last post by:
Hello everyone. I am experiencing a strange problem that I can't fix on my own. I think I need expert's suggestions for this. The problem is: I want to print account statement (or any other...
5
Stang02GT
by: Stang02GT | last post by:
I have been asked to validate a date on our web-page so that people cannot enter dates like 14/1/08 or 2/30/06. I have found code that will do exactly what i need it to do, but i am not sure how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.