473,394 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,394 software developers and data experts.

DateTime question!

Is it possible to check a datetime value as in which culture format?
My program is written for international customers. I have a function
which converts the date and time to en-US format and is working. But I
want to check before converting to see if the date and time is already
in en-US format? Can I do this without using Try and catch?

Thanks.

Mar 30 '07 #1
6 1330
On Mar 30, 2:25 pm, "DBC User" <dbcu...@gmail.comwrote:
Is it possible to check a datetime value as in which culture format?
No. A DateTime is just a point in time (well, nearly - there are
timezone issues too).
My program is written for international customers. I have a function
which converts the date and time to en-US format and is working. But I
want to check before converting to see if the date and time is already
in en-US format? Can I do this without using Try and catch?
That's like saying:

double x = 10.5;

Is that double in European format ("10,5") or English format ("10.5")?
The answer is neither - the number is just a number. It's only when
you format it that it takes on any cultural significance.

Jon

Mar 30 '07 #2
On Mar 30, 8:29 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Mar 30, 2:25 pm, "DBC User" <dbcu...@gmail.comwrote:
Is it possible to check a datetime value as in which culture format?

No. A DateTime is just a point in time (well, nearly - there are
timezone issues too).
My program is written for international customers. I have a function
which converts the date and time to en-US format and is working. But I
want to check before converting to see if the date and time is already
in en-US format? Can I do this without using Try and catch?

That's like saying:

double x = 10.5;

Is that double in European format ("10,5") or English format ("10.5")?
The answer is neither - the number is just a number. It's only when
you format it that it takes on any cultural significance.

Jon
Hi Jon,

Thanks and I understand your point. In my case, the data is stored in
a XML file created by another process that I don't have control over.
So I want to read the data correct.
The reason for my questions is, in production I ran into a situation,
where one element was stored in de-DE (local culture, without am/pm
and 24 hour clock) format and another element was stored in en-US
format as strings. Now when I read the data, I want to make sure I am
not blindly convert all the datetime string from current culture to US
since, some of them are already in US format.
So I thought I will put a check first before converting.

Mar 30 '07 #3
On Mar 30, 2:44 pm, "DBC User" <dbcu...@gmail.comwrote:
Thanks and I understand your point. In my case, the data is stored in
a XML file created by another process that I don't have control over.
So I want to read the data correct.
Ah, in that case you don't have a DateTime to start with - you have a
String. That's a completely different matter :)

Rather than checking for different formats in your code, I'd find out
(for sure) what the other process will create - and try it in
different cultures. If it's sensible, it'll stick to one format. Then
again, there's plenty of code around which isn't sensible...

Jon

Mar 30 '07 #4
On Mar 30, 8:46 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Mar 30, 2:44 pm, "DBC User" <dbcu...@gmail.comwrote:
Thanks and I understand your point. In my case, the data is stored in
a XML file created by another process that I don't have control over.
So I want to read the data correct.

Ah, in that case you don't have a DateTime to start with - you have a
String. That's a completely different matter :)

Rather than checking for different formats in your code, I'd find out
(for sure) what the other process will create - and try it in
different cultures. If it's sensible, it'll stick to one format. Then
again, there's plenty of code around which isn't sensible...

Jon
I agree with your last part and the 3rd party group will not release
fix for this issue for another couple of months and that also I am not
sure. (one of the reason is, their product is supposed to be the end
product, but I am scaling it and that they don't like).
So I thought, all I have to do is check and see if the string is in US
format by forcing a datetime pharse on US and if it fails (with try
and catch), then try to pharse it in native format. But woundering if
there is a better way.

Mar 30 '07 #5


"DBC User" <db*****@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
On Mar 30, 8:46 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
>On Mar 30, 2:44 pm, "DBC User" <dbcu...@gmail.comwrote:
Thanks and I understand your point. In my case, the data is stored in
a XML file created by another process that I don't have control over.
So I want to read the data correct.

Ah, in that case you don't have a DateTime to start with - you have a
String. That's a completely different matter :)

Rather than checking for different formats in your code, I'd find out
(for sure) what the other process will create - and try it in
different cultures. If it's sensible, it'll stick to one format. Then
again, there's plenty of code around which isn't sensible...

Jon

I agree with your last part and the 3rd party group will not release
fix for this issue for another couple of months and that also I am not
sure. (one of the reason is, their product is supposed to be the end
product, but I am scaling it and that they don't like).
So I thought, all I have to do is check and see if the string is in US
format by forcing a datetime pharse on US and if it fails (with try
and catch), then try to pharse it in native format. But woundering if
there is a better way.
How can you be sure that it is in en-us?

10-11-2007 could be oct 11th, 2007 or Nov 10th, 2007...

HTH,
Mythran
Mar 30 '07 #6
On Mar 30, 10:51 am, "Mythran" <kip_pot...@hotmail.comwrote:
"DBC User" <dbcu...@gmail.comwrote in message

news:11**********************@o5g2000hsb.googlegro ups.com...


On Mar 30, 8:46 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Mar 30, 2:44 pm, "DBC User" <dbcu...@gmail.comwrote:
Thanks and I understand your point. In my case, the data is stored in
a XML file created by another process that I don't have control over.
So I want to read the data correct.
Ah, in that case you don't have a DateTime to start with - you have a
String. That's a completely different matter :)
Rather than checking for different formats in your code, I'd find out
(for sure) what the other process will create - and try it in
different cultures. If it's sensible, it'll stick to one format. Then
again, there's plenty of code around which isn't sensible...
Jon
I agree with your last part and the 3rd party group will not release
fix for this issue for another couple of months and that also I am not
sure. (one of the reason is, their product is supposed to be the end
product, but I am scaling it and that they don't like).
So I thought, all I have to do is check and see if the string is in US
format by forcing a datetime pharse on US and if it fails (with try
and catch), then try to pharse it in native format. But woundering if
there is a better way.

How can you be sure that it is in en-us?

10-11-2007 could be oct 11th, 2007 or Nov 10th, 2007...

HTH,
Mythran- Hide quoted text -

- Show quoted text -
Good question and that I don't. I have another question, if I have the
following code, will all my pharsing and storing will be in the
culture specified?

Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo("en-US");

Thanks.

Mar 30 '07 #7

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

Similar topics

3
by: Grant Edwards | last post by:
Is it true that a datetime object can convert itself into a string, but not the other way around? IOW, there's no simple way to take the output from str(d) and turn it back into d? So, I tried...
6
by: Carl | last post by:
Hi, to be use with SQL server database 1- From window form textbox object From this assignement, txtTOTAL.Text="0.00m"; How do you convert back to decimal type ? How do you assign a...
8
by: Jimmie | last post by:
Hiya all, very quick question, I hope .. I have an xml dump of some old data that I need to parse and input into a new system. A couple of date fields are in there that have the following data...
3
by: Andrew S. Giles | last post by:
Hello, I am importing a flat text file, and putting it into a datagrid for display on a form. Currently the users have their dates and times seperated. I have two fields, therefore in the...
8
by: Alan Silver | last post by:
Hello, I have a custom control that displays the date and time. I currently have properties for the day, month, year, hour and minute, which have to be set separately. This is inefficient. I...
26
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM'...
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
4
by: Philippe Martin | last post by:
Hi, I need to get the date and time under Windows and Linux but need the information visible to the user (cannot find my words) not the sytem information (ex: a PC setup on greenwich but the...
5
by: iulian.ilea | last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy into it? I choose this method because I have an application that runs on more than one server. So, if I used a datetime field...
0
by: maolimix | last post by:
Hi to all, I have a trouble with datetime...now I explain.. I must to store to a C# variable the values from a "Datetime column" of Sql Server 2005. I tried 3 methods ...in the first two I never...
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
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
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
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.