473,405 Members | 2,338 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,405 software developers and data experts.

DateTime Just Month and Year

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-
Oct 4 '07 #1
2 9554
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");

--
Chris Mullins
"Joe Tavares" <Jo********@discussions.microsoft.comwrote in message
news:D3**********************************@microsof t.com...
>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-

Oct 4 '07 #2
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

Oct 5 '07 #3

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

Similar topics

14
by: Paul Moore | last post by:
I was just writing some code which did date/time manipulations, and I found that the Python 2.3 datetime module does not supply a number of fairly basic functions. I understand the reasoning (the...
4
by: Rob Conner | last post by:
So this is simple, why can't I run the following code? I've tried many variances of this, but simply cannot inherit from datetime or datetime.datetime. I get this on line 3. TypeError: function...
2
by: ThomasR | last post by:
I've done some examination of the DateTime implementation (stepped through Disassembly in debug mode) and find it horribly inefficient in framework 1.0. For example, the internal DatePart...
6
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference...
4
by: gabor | last post by:
hi, i'm trying to get the date of the day one month ago. for example: today = 12.apr.2006 one-month-ago = 12.mar.2006 so:
10
by: David P. Donahue | last post by:
Can anyone think of an easy way to take two DateTime values and calculate, with double precision, how many semi-monthly (the first and the fifteenth) pay periods occur between them? I started...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
14
by: shapper | last post by:
Hello, I have two nullable DateTime: begin and end. I need to find the range, in month, between both variables. If for some reason, for example begin is null, it is not possible to calculate...
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.