🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #23844

SQL, Dates and MS Access Databases

#23844
From: Randy K. Secrist
Date: Sun, 16 Sep 2001 15:32
39 lines
3110 bytes
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: <zC3p7.63$%W3.128769@news.uswest.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed.news.qwest.net!news.uswest.net.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f5d71,5e897627a3332cb9,start
X-Google-Attributes: gidf5d71,public
X-Google-Thread: 113ae9,5e897627a3332cb9,start
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 10a146,5e897627a3332cb9,start
X-Google-Attributes: gid10a146,public
X-Google-Thread: f6cb0,5e897627a3332cb9,start
X-Google-Attributes: gidf6cb0,public
X-Google-Thread: 111d6b,5e897627a3332cb9,start
X-Google-Attributes: gid111d6b,public
X-Google-ArrivalTime: 2001-09-16 08:32:48 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed.news.qwest.net!news.uswest.net.POSTED!not-for-mail
From: "Randy K. Secrist" <r.secrist@m.cc.utah.edu>
Newsgroups: cn.bbs.comp.lang.java,comp.lang.java,comp.lang.java.help,comp.lang.java.misc,comp.lang.java.programmer
Subject: SQL, Dates and MS Access Databases
Lines: 43
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: <zC3p7.63$%W3.128769@news.uswest.net>
Date: Sun, 16 Sep 2001 09:32:45 -0600
NNTP-Posting-Host: 63.226.106.233
X-Trace: news.uswest.net 1000654367 63.226.106.233 (Sun, 16 Sep 2001 10:32:47 CDT)
NNTP-Posting-Date: Sun, 16 Sep 2001 10:32:47 CDT