Article View: cn.bbs.comp.lang.java
Article #23846Re: SQL, Dates and MS Access Databases
From: Michele Ouellet
Date: Mon, 17 Sep 2001 10:36
Date: Mon, 17 Sep 2001 10:36
66 lines
3827 bytes
3827 bytes
Hi! I have been using a type Date/Time to store dates in MS-Access. I insert dates as strings using a long format. The format used for the "General Date Format" in Access seem to agree with that in the Windows Control Panel Settings. When I do the type of calculation you need, I parse the string back into a Date, using a SimpleDateFormat. Not elegant, and not thoroughly tested, but it seems to work. Bye, Mich๏ฟฝle. "Randy K. Secrist" <r.secrist@m.cc.utah.edu> wrote in message news:zC3p7.63$%W3.128769@news.uswest.net... > Help! > > Does anyone know how to get the number of exact days since or before a > specific time period? If you think you can help, let me describe what I am > doing below... > > I am inserting rows into an access database. One of the columns I am adding > is a date field. Normally using Oracle or DB2, I can instantiate a > java.util.Date, and insert the variable directly in the insert statement, > and the correct date gets inserted into the database. > > However, in this case, the people I am doing a program for are set on using > MS Access. *Sigh*. The driver throws an exception if I use a > java.util.Date, and if I use a java.sql.Date it successfully inserts the > field into the database, but the wrong date is added to the row. So, after > experimenation, i noticed that to get the correct date into the database, > the SQL insert statment must have the date fields is just really a regular > integer that looks like this: > > 0 being December 30 1899 > 1 being December 31 1899 > 2 being Jan 01, 1900 > 3 being Jan 02, 1900 etc. > > 25569 being Jan 01, 1970 > > Since java tracks time in miliseconds from Jan 01 1970 - 12:00 AM being > around 2703600000 miliseconds, i started to do this the hard way - to get > the number of days since 01/01/1900 from the number of miliseconds since > 1970 - writing all kinds of methods to divide and get the miliseconds right. > > So far this work around seems to work for 1900 to 2100 years, but if I go > back far in time, say to 1700 it starts getting off by a few days. For all > i know it has to do with leap years, and the such. Basically I don't want > to write a whole date class just to get the number of days... does anyone > have solutions that could save me a lot of time and hassle? I'd really > appreciate it.... > > Randy Secrist > > > >
Technical Details
Message-ID:
<4okp7.3542$85.1276818@weber.videotron.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sunqbc.risq.qc.ca!wesley.videotron.net!weber.videotron.net.POSTED!not-for-mailReferences:
<zC3p7.63$%W3.128769@news.uswest.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10a146,5e897627a3332cb9 X-Google-Attributes: gid10a146,public X-Google-Thread: 111d6b,5e897627a3332cb9 X-Google-Attributes: gid111d6b,public X-Google-Thread: f6cb0,5e897627a3332cb9 X-Google-Attributes: gidf6cb0,public X-Google-Thread: 113ae9,5e897627a3332cb9 X-Google-Attributes: gid113ae9,public X-Google-Thread: f5d71,5e897627a3332cb9 X-Google-Attributes: gidf5d71,public X-Google-ArrivalTime: 2001-09-17 03:37:52 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sunqbc.risq.qc.ca!wesley.videotron.net!weber.videotron.net.POSTED!not-for-mail From: "Michele Ouellet" <ouellmi@tvideotron.ca> Newsgroups: cn.bbs.comp.lang.java,comp.lang.java,comp.lang.java.help,comp.lang.java.misc,comp.lang.java.programmer References: <zC3p7.63$%W3.128769@news.uswest.net> Subject: Re: SQL, Dates and MS Access Databases Lines: 68 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: <4okp7.3542$85.1276818@weber.videotron.net> Date: Mon, 17 Sep 2001 06:36:16 -0400 NNTP-Posting-Host: 24.203.59.70 X-Complaints-To: abuse@videotron.ca X-Trace: weber.videotron.net 1000723072 24.203.59.70 (Mon, 17 Sep 2001 06:37:52 EDT) NNTP-Posting-Date: Mon, 17 Sep 2001 06:37:52 EDT