Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to identify whether a Data contains a calendar date or time

Status
Not open for further replies.

tom62

Programmer
Nov 12, 2002
152
0
0
DE
I'm reading timestamps from an unknown database table (in my case from an MS-Access database). Since I don't know the date/time format of the timestamps the fields could contain a calendar date, a calendar date + time or a time (without the date).

Is there a way to identify whether the java.sql.TimeStamp object is a date, a time or both?
 
I would use a simpledateformat and try. Like
Code:
SimpleDateFormat df = new SimpleDateFormat("MM/dd/y");
try {d = df.parse([red]<your value>[/red]);}

_________________
Bob Rashkin
 
Thanks for your reply. The problem is that the java.sql.TimeStamp doesn't countain a null date. For MS-Access timestamps this date is set by default to 1899-12-30, while the default date in java.sql.Date is 1970-01-01.
The SimpleDateFormat.parse will therefore always succeed,

What I need to find out is which format is used in the database table to display the date or time. I've tried to use DatabaseMetaData to read the structure of the table, but haven't located this format yet.
 
There is a jdbc-driver for MsAccess?

I guess if you read all the rows and one timestamp isn't 00:00:00, you got a date/time field.

On the other hand, if all fields are 00:00:00, you won't know it for sure.

don't visit my homepage:
 
The standard Sun jdbc-driver for M$Access is unsuitable for that task. I could try to see whether a commercial driver would get me the information that I need, but I'm not really willing to invest loads of money for my freeware application.

The easiest way to solve the problem is probably to let the users define themselves what the correct format is, in case my program finds a date in the timestamp that corresponds with the default date.

in pseudo-code:

if (date part of time stamp == default date) then
prompt user for the correct date/time format
else
// time stamp != time
if (time part of time stamp == "00:00:00") then
// time stamp == date only
else
// time stamp == date and time

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top