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

Storing Any Date

Is it possible to store dates before 01/01/0100 A.D. (such as for as database storing world events would require) using MS Access?

Verbose Explination

I need to be able to store dates before 100CE in a date field. This is for a world history database that I am building. I am currently storing dates in a database as unformatted text (14 characters: mm/dd/yyyy/[BCE|CE/]. This requires using alot of extra VBA code to validate the dates to ensure they are indeed valid dates and in a valid format. Using a date field, I figure that I can store dates from 01/01/9999 BCE to 12/31/0100 BCE and from 01/01/0100 CE to 12/31/9999 CE by storing a date in one field and BCE or CE in another field. However, these leaves a gap from 01/01/0099 BCE to 12/31/0099 CE that cannot be accounted for (a 197 year, 363 day gap by my calculations). Using this method would make it much easier to sort dates and also find the amount of time between two dates. Is this possible or is the method I am using the best way for this (I am currently using split on the date using the / as the character to explode the value)?
Mar 28 '07 #1
7 3218
nico5038
3,080 Expert 2GB
Access will store dates in a numeric field being a relative daynumber.
This daynumber starts at 30-december-1899.
To get dates before the 30th December 1899 the relative daynumber will be made negative. This way the datediff will give correct results and I guess also for BC dates.

Nic;o)
Mar 30 '07 #2
So is that a no?
Mar 30 '07 #3
NeoPa
32,556 Expert Mod 16PB
I think it is within a Date/Time field I'm afraid.
It is possible, of course, to store dates as text instead. You would lose the ability to process or calculate on them as dates but you could handle most things I would have thought.
For date sorting in text you'd need the dates to be stored highest element first downwards. IE Year; Month; Day. Each element would have to be formatted to fit in a fixed length portion of the string (Years 5 chars to handle '-' - AD & BC would sort the wrong way unfortunately).
Alternatively, do something with a Long Integer, but I think that dates (as opposed to simple years) would require too many digits even for a Long.
Mar 30 '07 #4
Thank you for the reply.

I think I am going to use an integer and a long to store the date. (48 bits/date = 6 bytes/date, less than the date field).

The integer will store the year, being from -32,768 to 32,767 with negative numbers being BCE and positive numbers being CE.

The long will store the day of the year and the time of day.
Expand|Select|Wrap|Line Numbers
  1. x = val(right(left(str(lngDay),6),3))
  2.  
will be used to get the day of the year (0-999, but only 0-365 will be used) and
Expand|Select|Wrap|Line Numbers
  1. y = val(right(str(lngDay),6))
  2.  
will be used to store the time of day. Any given time can be encoded as a series of number representing the decimal part of the day. For instance, there are 1440 minutes in the day. If it is 2:41 PM (14:31), then (14*60) + 31 minutes have passed = 871 minutes. Therefore I could use
Expand|Select|Wrap|Line Numbers
  1. y = val(right(left(str(871/1440),8),6))
  2.  
to get the numeric value for the portion of the day, which in this case would be 604861.

Then I could just use the equation:
lngDayOfYear = (intDay * 1000000) + val(right(left(str(intHour*60 + intMinutes/1440),8),6))
to store the day and time and
intDay = val(right(left(str(lngDay),6),3))
intTime = round(val(right(str(lngDay),6))*1440)
to retrieve it. This would give me the minutes which could easily be turned into hours and minutes using modulo and division operators.

As an example, today and right now (March 31, 2007, 1:05 PM) could be stored as
intYear = 2,007
lngDay = 90,545,139
Mar 31 '07 #5
NeoPa
32,556 Expert Mod 16PB
There's no reason you couldn't get that to work, but as most usages involve converting to string anyway, why complicate matters?
It wouldn't make much difference mind you so not a problem really.
Mar 31 '07 #6
The reason I use numbers instead of strings it because they take up less space in the database. A date stored in a string that was 2 characters for the day, 2 for the month, 5 for the year, and 4 for the time would take up 13 bytes per date plus the space to store a string (4 bytes if I remember correctly, meaning 17 bytes total per). Storing it as a number would decrease the size to 6 bytes per date (2 bytes for the year, 4 for the day and time). The math is relatively easy to get the date to store it and retrieve it. The space is more vital. While the difference at this scale doesn't amount to much (11 bytes), when you consider a database with, say, around 100,000 records (which is what it will start at), that amounts to 11 bytes * 100,000 records = 1,100,000 bytes difference (1074.2 KB or 1.049 MB). The size difference is important for this application because it could easily span up to 10,000,000 records, equating to ~100MB difference.

(To be exact, using numerals =
6.00 B / Record * 10,000,000.00 Records = 60,000,000.00 B = 58,593.75KB = 57.22 MB
17.00 B / Record * 10,000,000.00 Records = 170,000,000.00 B = 166,015.63 KB = 162.12MB
162.12MB - 57.22MB = 104.9MB = 107,417.60 KB = 109,995,622.40 B

I appreciate the input but for this application I can't afford to use strings ^.^ Thank you for answering my question, however.
Apr 1 '07 #7
NeoPa
32,556 Expert Mod 16PB
Very good reason :D
Bear in mind that these will be stored in fields within records which may be constrained to Word &/or Double-Word boundaries so the saving may not be precisely as calculated. Nevertheless, there will surely be considerable savings over so many records. Good choice.
Apr 2 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
4
by: m3ckon | last post by:
HI there, I currently store the date using the getdate() function but how can I store just the time or seperate the time off from a datetime datatype? M3ckon *** Sent via Devdex...
2
by: Robert | last post by:
I have no problem storing dates + times in a System.DateTime object. In addition, it's easy to output a Time as a string from an existing Date/Time. But I'm having trouble storing a time only. ...
1
by: Thomas R. Hummel | last post by:
Hello all, I have been working with several databases here that are basically data marts. A lot of the entities have an attribute that is a particular year and month. For example, a financial...
8
by: Zvonko | last post by:
Hi! I would like to get the clients date and time (his system time) and store it somewhere so I can use it in my code later. (insert it to database!). Any ideas Zvonko
4
by: Hazzard | last post by:
What is the best way to do this? Binary with 0 representing off and 1 on? Int16 with 1 representing first button, 2 the second, 3 ... varchar with a character values at certain positions in the...
2
by: David Garamond | last post by:
What would be the more proper way of storing birthday data? It will be used to send out birthday messages for customers ("Happy 30th birthday, Sam!"). But the date of birth is not necessarily known...
11
by: James Hallam | last post by:
I have read through all the past topics and couldn't find what I was after so... I am looking to store some calculated values (don't flame just yet, just read on!). I have an piece of code...
4
by: John A Grandy | last post by:
What are some best practices for storing pure dates and pure times in .NET ? I notice that DateTime.TimeOfDay() returns type TimeSpan , which is certainly sufficient for storing pure times , but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.