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

Date format causing great problems!

I have an application which imports fields from external source where
date format of one the collumns is English (United States): M/d/yyyy.
So July 1, 2005 equals to: 7/1/05
I am using this date everywhere in the application.

Problem is when someones is lets say in Portugal with the regional
settings for date set to DD-MM-YYYY.

I am going crazy to figure out how to make everyone to use M/d/yyyy
scheme without changing their regional settings, as lots of people
simply can't do that.

Can someone point me to what I could do, or post some code on how to go
around this annoying problem?

It would be very much appreciated.

Joe

Nov 17 '05 #1
9 2066

"Jozef Jarosciak" <jo*@doprocess.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I have an application which imports fields from external source where
date format of one the collumns is English (United States): M/d/yyyy.
So July 1, 2005 equals to: 7/1/05
I am using this date everywhere in the application.

Problem is when someones is lets say in Portugal with the regional
settings for date set to DD-MM-YYYY.

I am going crazy to figure out how to make everyone to use M/d/yyyy
scheme without changing their regional settings, as lots of people
simply can't do that.

Can someone point me to what I could do, or post some code on how to go
around this annoying problem?

It would be very much appreciated.

Joe


One way to is to detect if the date coming in is non US and then do some
type of transforming on it. You mention external source. Is there
something coming with the data to signify its country or at least that it is
non US? What is the data type they are sending back?

Use some of the DateTime methods to return a date against your imported
date. Then you can go further to pick it apart by hours, minutes, month,
year if you need to. From that you can construct the date format you need
or possibly just format off of the returned date if DateTime allows.

Brett
Nov 17 '05 #2
Hi Brett,
I need some one liner, code which would set the whole program (form) to
"M/d/yyyy" so whenever I do have to deal with date it would forget
about my users DD-MM-YYYY format and assume they all have "M/d/yyyy".
Is there any way to ignore regional settings and its date format?
Joe

Nov 17 '05 #3

"Jozef Jarosciak" <jo*@doprocess.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi Brett,
I need some one liner, code which would set the whole program (form) to
"M/d/yyyy" so whenever I do have to deal with date it would forget
about my users DD-MM-YYYY format and assume they all have "M/d/yyyy".
Is there any way to ignore regional settings and its date format?
Joe


Have you tried
DateTime.Parse(TextBox1.Text).ToString("M/d/yyyy");

Are users editing this data in the form or does it appear from you import as
read only to them?

Brett
Nov 17 '05 #4
It is usually best to let users enter dates (and numbers) in the format they
are most familiar with. Trying to force them to do otherwise will only lead
to data entry errors.

The date format only matters when your application interacts with the
'outside world', i.e. your users or the database. Within the application,
the DateTime variables are independent of their value's textual
representation.

In your external interactions, use the appropriate CultureInfo object, which
you can then pass as the IFormatProvider argument to the DateTime's Parse or
ToString methods as appropriate.

The current user's CultureInfo is available through the CurrentUICulture
property of CultureInfo. It sounds like your database uses a specific
culture, for example: "new CultureInfo("EN-US")"

For more information, including code samples, look up these class and
interface names in the .NET framework documentation.

Jeffrey Sax
Extreme Optimization
http://www.extremeoptimization.com

"Jozef Jarosciak" <jo*@doprocess.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I have an application which imports fields from external source where
date format of one the collumns is English (United States): M/d/yyyy.
So July 1, 2005 equals to: 7/1/05
I am using this date everywhere in the application.

Problem is when someones is lets say in Portugal with the regional
settings for date set to DD-MM-YYYY.

I am going crazy to figure out how to make everyone to use M/d/yyyy
scheme without changing their regional settings, as lots of people
simply can't do that.

Can someone point me to what I could do, or post some code on how to go
around this annoying problem?

It would be very much appreciated.

Joe

Nov 17 '05 #5
One example of what Jeffrey is talking about is:

IFormatProvider culture = new CultureInfo("en-US", true);
string DateTimeEnValue = DateTime.Now.ToString();
string myShortEnglishDate = DateTimeEnValue .ToShortDateString();

Brett

"Jeffrey Sax" <in**@extremeoptimization.com> wrote in message
news:E7********************@rogers.com...
It is usually best to let users enter dates (and numbers) in the format
they are most familiar with. Trying to force them to do otherwise will
only lead to data entry errors.

The date format only matters when your application interacts with the
'outside world', i.e. your users or the database. Within the application,
the DateTime variables are independent of their value's textual
representation.

In your external interactions, use the appropriate CultureInfo object,
which you can then pass as the IFormatProvider argument to the DateTime's
Parse or ToString methods as appropriate.

The current user's CultureInfo is available through the CurrentUICulture
property of CultureInfo. It sounds like your database uses a specific
culture, for example: "new CultureInfo("EN-US")"

For more information, including code samples, look up these class and
interface names in the .NET framework documentation.

Jeffrey Sax
Extreme Optimization
http://www.extremeoptimization.com

"Jozef Jarosciak" <jo*@doprocess.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I have an application which imports fields from external source where
date format of one the collumns is English (United States): M/d/yyyy.
So July 1, 2005 equals to: 7/1/05
I am using this date everywhere in the application.

Problem is when someones is lets say in Portugal with the regional
settings for date set to DD-MM-YYYY.

I am going crazy to figure out how to make everyone to use M/d/yyyy
scheme without changing their regional settings, as lots of people
simply can't do that.

Can someone point me to what I could do, or post some code on how to go
around this annoying problem?

It would be very much appreciated.

Joe


Nov 17 '05 #6
I am sorry, but this is a spanish village for me.
Can someone show me on simple example how I force my whole application
to use en-US format?
I don't use threads in my program, so I can't apply cultureinfo to
thread.

Imagine this.
Simple case scenario:
I ask for datetime.now and it gives me: 7/1/2005
But my user gets: 1/7/2005
So when I further ask for day of the week, which I want to highlight,
it is all screwed up, as it thinks it's 7th of January as opose to
correct 1 of July.

I need a way to force the whole program to think user is in USA with US
regional settings for date.

Is there a way to do this?
Joe

Nov 17 '05 #7
This is a fix I found in vb.net and worked like a charm for me.
Dim ci As New System.Globalization.CultureInfo("en-US", False)
Dim newCi As System.Globalization.CultureInfo =
CType(ci.Clone(), System.Globalization.CultureInfo)
newCi.DateTimeFormat.AMDesignator = "AM"
newCi.DateTimeFormat.PMDesignator = "PM"
newCi.DateTimeFormat.ShortDatePattern = "M/d/yyyy"
Thread.CurrentThread.CurrentCulture = newCi

Just wanted to post it and share it with other. Now my whole
application is switched to en-US format, no matter what country is my
user from.
Joe

Nov 17 '05 #8
What search keywords did you use to find the code?

Nice that you got it.

Brett

"Jozef Jarosciak" <jo*@doprocess.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
This is a fix I found in vb.net and worked like a charm for me.
Dim ci As New System.Globalization.CultureInfo("en-US", False)
Dim newCi As System.Globalization.CultureInfo =
CType(ci.Clone(), System.Globalization.CultureInfo)
newCi.DateTimeFormat.AMDesignator = "AM"
newCi.DateTimeFormat.PMDesignator = "PM"
newCi.DateTimeFormat.ShortDatePattern = "M/d/yyyy"
Thread.CurrentThread.CurrentCulture = newCi

Just wanted to post it and share it with other. Now my whole
application is switched to en-US format, no matter what country is my
user from.
Joe

Nov 17 '05 #9
> Can someone show me on simple example how I force my whole application
to use en-US format?

Sorry, but what all are trying to explaint is that this is really
a bad thing to do.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
------------------------------------------
Replace _year_ with _ to get the real email
Nov 17 '05 #10

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

Similar topics

10
by: Fawke101 | last post by:
Hi there, I have a date field in SQL server - that holds dates as DD/MM/YYYY format (GB). Now, i have an ASP application that Adds/Edits records in this table; and i am having real problems...
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...
13
by: Deano | last post by:
Hi, I generate a report using two dates (From and To). I notice if I enter 01/10/2003 that it is interpreted by Access as 10/01/2003 i.e 10th January rather than 1st October as I intended. ...
1
by: Dave | last post by:
Hi, I have a Sales database with two fields (actually more thaqn 2 but these are causing me grief :), one is call and is format as dd-mm-yyyy and the other is called day with the record source as...
3
by: Jozef Jarosciak | last post by:
I have an application which imports fields from external source where date format of one the collumns is English (United States): M/d/yyyy. So July 1, 2005 equals to: 7/1/05 I am using this date...
3
by: Chu | last post by:
In playing with asp.net 2.0, I've been impressed with the internationalization support that's built right in. It's great that I can simply add a tag to my page's directive and it magically...
9
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i...
2
by: savigliano | last post by:
hello, i am doing a date comparation and i have reallize that the data i have in my database (general date format) it is causing me problems, and because i donīt need the time data i would like to...
3
by: rn5a | last post by:
In my local computer, date has been set in this format - dd/MM/yyyy. When I insert records in a MS-Access DB table using ASP.NET, then the records get inserted in the Access DB table exactly in the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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,...

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.