473,385 Members | 1,676 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.

Problem with ToShortDateString()

Hi

I am using .NET v2.0 and recently sent an app to a client site that was
working correctly in our office (SQLServer 2005 Express). When setting a
date I use ToShortDateString() on a DateTime object and am getting back a
string in the form '2005-08-31'

However, at the new client site, (SQL Server 2005), the exact same
executable is producing the string '05-08-31', which does not work too well
when I want to set dates before 2000.

Can someone please explain what is happening, and, more importantly, what I
can do to fix it?

Thanks in advance,
Chris Hough
Jun 27 '08 #1
11 2097
On 20/06/2008 in message <uA**************@TK2MSFTNGP03.phx.gblChris
Hough wrote:
>Hi

I am using .NET v2.0 and recently sent an app to a client site that was
working correctly in our office (SQLServer 2005 Express). When setting a
date I use ToShortDateString() on a DateTime object and am getting back a
string in the form '2005-08-31'

However, at the new client site, (SQL Server 2005), the exact same
executable is producing the string '05-08-31', which does not work too
well when I want to set dates before 2000.

Can someone please explain what is happening, and, more importantly, what
I can do to fix it?

Thanks in advance,
Chris Hough
What does your client have set up as the short date string in Regional
Settings?

--
Jeff Gaines Damerham Hampshire UK
All those who believe in psychokinesis raise my hand.
Jun 27 '08 #2

"Chris Hough" <sa***@pcTrans.comwrote in message
news:uA**************@TK2MSFTNGP03.phx.gbl...
Hi

I am using .NET v2.0 and recently sent an app to a client site that was
working correctly in our office (SQLServer 2005 Express). When setting a
date I use ToShortDateString() on a DateTime object and am getting back a
string in the form '2005-08-31'

However, at the new client site, (SQL Server 2005), the exact same
executable is producing the string '05-08-31', which does not work too
well when I want to set dates before 2000.

Can someone please explain what is happening, and, more importantly, what
I can do to fix it?
Forget the ToShortDateString(), as you can format using the ToString() with
ToString("yy-dd-MM") as an example, look it up with Google on how to use the
ToString() and formatting dates, using ToString().

Also, if I recall, the date format for short and long date that will be
returned is machine O/S independent. You can check this by looking at the
Regional and Language settings for the O/S. I think you might be able to
override this with a .Net setting, but that is a maybe.


Jun 27 '08 #3
Thank you for the reply.

Can you please tell me how to check what they have set up as the short date
string in Regional Settings?
Jun 27 '08 #4

"Chris Hough" <sa***@pcTrans.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Thank you for the reply.

Can you please tell me how to check what they have set up as the short
date string in Regional Settings?
Control Panel/Regional Options or Regional and Languages on Vista

Jun 27 '08 #5
Chris,

As a system is set to by instance a Chinese or Swedish setting (where ISO
are used), then 05 08 31 does mean
31th of August in the year 2005

In all other culture cases the by you showed date time is impossible

Therefore you have to look what culture setting is used, and if that is not
an ISO culture then as Arnold wrote if somebody maybe has played with the
datetimes setting to force a kind of ISO (what it is not what you get
returned).

However I am currious in what kind of application you are working because
for me is clear that 99-05-31 is 31 june 1999

Cor

"Chris Hough" <sa***@pcTrans.comschreef in bericht
news:uA**************@TK2MSFTNGP03.phx.gbl...
Hi

I am using .NET v2.0 and recently sent an app to a client site that was
working correctly in our office (SQLServer 2005 Express). When setting a
date I use ToShortDateString() on a DateTime object and am getting back a
string in the form '2005-08-31'

However, at the new client site, (SQL Server 2005), the exact same
executable is producing the string '05-08-31', which does not work too
well when I want to set dates before 2000.

Can someone please explain what is happening, and, more importantly, what
I can do to fix it?

Thanks in advance,
Chris Hough
Jun 27 '08 #6
Date formatting is a big problem if your app is supposed to be used in
multiple cultures. I think you should consider using the cultureinfo
class to get some meaning out of the format.

Meanwhile, for a stop-gap solution, using literal string formats like
MM-dd-yyyy is a fine idea.

In my applications i use the literal date-time string cause they're
culture specific

Regard
cyril gupta
Jun 27 '08 #7
Cyril,
Meanwhile, for a stop-gap solution, using literal string formats like
MM-dd-yyyy is a fine idea.
Be aware that this can only be used localy in the USA, not even in Canada.

Cor
Jun 27 '08 #8

The short date setting for the offending computer is: 6/23/2008 - it appears
to be no different from the computers that are working properly.

I don't see how it can be safe to format the date string myself, as must
this not run the risk of mixing up the day and month? i.e. if I set the date
string in my program to be: '1930-01-02', how does SQL Server know whether
this is January 2nd or February 1st?

What is the tie in between the result from ToShortDateString() and what
happens on the SQL Server end - it seems as though there must be some way
that either .NET 'knows' or that SQLServer 'knows' which is the day and
which is the month. As we have clients in both US and Canada, I need a
comprehensive solution.

Regards,
Chris Hough
Jun 27 '08 #9
On 23/06/2008 in message <eo**************@TK2MSFTNGP04.phx.gblChris
Hough wrote:
>I don't see how it can be safe to format the date string myself, as must
this not run the risk of mixing up the day and month? i.e. if I set the
date string in my program to be: '1930-01-02', how does SQL Server know
whether this is January 2nd or February 1st?
I don't keep dates or times in any database, I convert them to an integer
index (days from a common start date and minutes from midnight) on the way
in and back to DateTime on the way out. It avoids any issues about how
different databases store dates and times.

--
Jeff Gaines Damerham Hampshire UK
Indecision is the key to flexibility
Jun 27 '08 #10

"Chris Hough" <sa***@pcTrans.comwrote in message
news:eo**************@TK2MSFTNGP04.phx.gbl...
The short date setting for the offending computer is: 6/23/2008 - it
appears to be no different from the computers that are working properly.

I don't see how it can be safe to format the date string myself, as must
this not run the risk of mixing up the day and month? i.e. if I set the
date string in my program to be: '1930-01-02', how does SQL Server know
whether this is January 2nd or February 1st?
If you have a concern about this, then you need to save the date as sting on
the SQL Server table and format it the way you need the date before you save
it to the table.

Jun 27 '08 #11
Chris,

Your server has to a mechanisme where it looks at the culture the server is
running on.

As we are using (Like mostly in Dutch) servers with US operating systems (To
get service pack and updates in the right timeand to prevent translating
errors), I never have any problem with date and times.

The mechanisme between SQL servers is different per server time field as you
probably know. SQL server 2008 is brought more inline with DotNet datetimes
although the old stay.

In fact as you keep far away from globalization settings, this mostly goes
well. As soon as you start toggling those settings wherever, you are mostly
direct or after a while in trouble.

The latter especially by using strings as date times because most people
beside developpers don't know about the different ways date times are
written in this world. I see often that Americans think that there way of
writting is global. However, AFAIK is the American way based on how dates
in English commonly where prononced in the 19th century.

Cor
"Chris Hough" <sa***@pcTrans.comschreef in bericht
news:eo**************@TK2MSFTNGP04.phx.gbl...
The short date setting for the offending computer is: 6/23/2008 - it
appears to be no different from the computers that are working properly.

I don't see how it can be safe to format the date string myself, as must
this not run the risk of mixing up the day and month? i.e. if I set the
date string in my program to be: '1930-01-02', how does SQL Server know
whether this is January 2nd or February 1st?

What is the tie in between the result from ToShortDateString() and what
happens on the SQL Server end - it seems as though there must be some way
that either .NET 'knows' or that SQLServer 'knows' which is the day and
which is the month. As we have clients in both US and Canada, I need a
comprehensive solution.

Regards,
Chris Hough
Jun 27 '08 #12

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

Similar topics

3
by: Billy Jacobs | last post by:
I have created a DataGridColumnDatePicker Component so that I can put a datetimepicker control in my datagrid. It almost works. When I put my mouse in the cell it changes to a datetimepicker...
11
by: Dieter Schwerdtfeger via DotNetMonster.com | last post by:
I have this function where i search through my database for items that were made on a specific date. The line "CType(dvClubs.Item(teller).Item(veld).ToShortDateString" gives me the error : option...
3
by: Stacey Levine | last post by:
I have a webservice that has the below procedure. Basically a procedure to called a stored procedure and return the results. When I try to call the webservice from my program I get the error. Both...
3
by: ad | last post by:
I want to transfer a DateTime variable to string. I use DateTime.ToShortDateString() to do that. But if the date is 2006 May 23, I want to it transfer to 2006/05/23, not 2006/5/23. How can I do?
2
by: Jesus | last post by:
Hi! I'm migrating a web application (ASP.NET) from Framework 1.1 to Framework 2.0. I have a problem with that, and I didn't found a solution changing something in web.config or something like...
1
by: massenza | last post by:
I have a combobox on my form. It is attached to a dataset and uses the values from datetimepicker's in the where clause. When the form opens, everything is retrieved correctly. When I change the...
3
by: girl | last post by:
i have this problem m using dataset dataadapter and dataset i would like to select a date range using a datetimepicker or monthcalendar. the data in my database for date is 05/01/2007 where 05...
0
by: jediknight | last post by:
I have a simple project where there is a master page called MasterPage.master and some webforms which are content pages. I also have a usercontrol which is a simple calendar control popup. The...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button 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: 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
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
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...

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.