DateTime Just Month and Year

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using the DateTime.Parse method to parse user entered dates. The dates
can be just the year, Month-year and Month-day-year in a variety of formats
in a variety of cultures. I immediately parse out the year case since I can
determine that very easily (ie it is 4 digits) and store a boolean to let me
know it is just a year.

The problem I am encountering is how to tell if a date has been entered with
just month year or month day year. For example, the following two entries
will result in the same DateTime value.

5/1/2007
5/2007

Also this will result in the same DateTime value

March 1, 2007
March 2007

I need to be able to differentiate the difference. I just need a way even on
parse to determine the difference. What are people's thoughts on the optimal
way to do this?

thanks for any help that people can supply,
-joe-
 
To take a quick stab:

if (Datetime.TryParseExact(datestring, "MMddyyyy", null, out result))
return result;
else if (Datetime.TryParseExact(datestring, "MMyyyy", null, out result))
return result;
else
throw new ArgumentException("Invalid Date Format");
 
Joe,

The answer is very simple, you can do that on a windows forms application as
soon as you know the culture. (Which is set (can be changed) in all
microsoft windows OS and easily to retrieve, then dates are automaticly
converted).

However with a webpage it is impossible as you cannot (without an accepted
applet and that will probably be prefented then by a security update) send
that culture with it (you can send the used language however that says, as
soon as it is by instance English, nothing about the used date format).
There is also somewhere a list with the IP addresses used in the world,
however that is as well gambling. By instance here in Holland somebody can
easily have American settings on his computer and then use the American
format.

In my idea is for interculture use better on webpages to create a box where
the dates parts can be hard coded set.

Cor
 
Back
Top