Roedy said:
You can use a convention, e.g. story YYYY-MM as if it were YYYY-MM-01.
At first I thought both Roedy and Thomas were oh so wrong, but I realize
that they read the original quote:
some data in this format: "mm/yyyy"
Meaning that the OP has a column of date all of which only has month
resolution. If so, they are right, just display it with less resolution
might be your ticket. If "some" applied to some of the rows in one
column then Libby is SOL, because 01/01/2006 00:00:00.00 stored in
either a java.util.Date or a DB DATETIME needs something else to tell us
if it is exactly that time or trying to represent the whole month of
January or even the whole year.
Others talked about an additional column which sort of implied that
they were thinking of there was mixed resolutions in one DATETIME column.
Libby, here are some things to consider:
but when I do format.parse() on "12/2001" it helpfully returns
December 1, 2001".
No, it returns a java.util.Date which when you call the toString()
either explicitly or when you are using System.out.print(myDate),
shows a millisecond value converted to localized String. Go back to
this code and consider always showing it to yourself while debugging and
to the user using a SimpleDateFormat as several others have
pointed out. If this consistency of simply ignoring the smaller fields
works your in business.
One thing to watch is to NOT take my suggestion and print out everything
in the Date wherever you have it in application (particularly right
before displaying to the user and right before shipping to the DB)
and make sure 2005-04-01 T 00:00:00.0000 (using ISO 8601 notation to
avoid any month day confusion in this discussion), doesn't magically
drift to 2005-01-04 T 15:34:17.1234 because you ran the application in
the afternoon and somehow you transfered the right date over the
present date time (just past 3:30 in the afternoon).
Meanwhile, your suggested use of SQL where you
"I will need to evaluate the stored "Date" to
determine if a day exists in it, and build the SQL accordingly. "
seem suspiciously unsual to me. I don't get how the word "the"
is imbedded in a real DATETIME as %theMm/yyyyDate%" and how you can use
the % operator on it. In fact, I'd be interested in knowing what DB you
are using and what SQL you can use. I dont' thing you want to have the
DB think in terms of Strings, but use SQL Date creating expressions to
specify the appropriate midnight-fixed DATETIME. Particularly watch
for comparing to not right NOW, but today at midnight with consideration
for when you want this mornings midnight or tonights.
Good luck, and don't be discouraged by people answering the
wrong question. Hopefully, I have answered the right question.
If not do let me know.
-Paul