473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date from Number of Days

I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old
database file that has the date(s) stored in it as number of days.
An example is: 36,525 represents 01/01/1900. The starting point date is considered to be :
00/00/0000. I have looked thru Help and used Google and have not really found an answer.
I know that Leap Years need to be accounted for too.
Any suggestions on where to start ?
james
Nov 21 '05 #1
29 9079
James,
Use DateTime.AddDay s to find a date given the number of days since a "well
known" date. Or to go the other direction use DateTime.Subtra ct to find the
number of days since a "well known" date.

The "problem" you are going to have is that Datetime.MinDat e is 01/01/0001
as opposed to 00/00/0000, I would simply add or subtract the difference in
days as needed...

You may want to consider a pair of functions, something like:

Private Const BaseDate As DateTime = #1/1/1900#
Private Const BaseDays As Integer = 36525

Public Function ToFileDateTime( ByVal value As DateTime) As Integer
Dim ts As TimeSpan = value.Date.Subt ract(BaseDate)
Return CInt(ts.TotalDa ys) + BaseDays
End Function

Public Function FromFileDateTim e(ByVal days As Integer) As DateTime
Return BaseDate.AddDay s(days - BaseDays)
End Function

Where BaseDate & BaseDays are your "well known" date.

Of course if you need dates pre 01/01/0001 then you may have a problem...

Hope this helps
Jay

"james" <jjames700ReMoV eMe at earthlink dot net> wrote in message
news:ed******** ******@TK2MSFTN GP11.phx.gbl...
I have a problem that at first glance seems not that hard to figure out.
But, so far, the answer has escaped me. I have an old database file that
has the date(s) stored in it as number of days.
An example is: 36,525 represents 01/01/1900. The starting point date is
considered to be :
00/00/0000. I have looked thru Help and used Google and have not really
found an answer.
I know that Leap Years need to be accounted for too.
Any suggestions on where to start ?
james

Nov 21 '05 #2
James,

Never done, however I think I would first bring it back to the date in ticks
at 00:00:00 hour and than use the normal datetime format.

http://msdn.microsoft.com/library/de...tickstopic.asp

I hope this helps something

Cor
Nov 21 '05 #3
Jay, great solution! Both functions work very well. After my brain kicked in and figured out how to use them correctly :-)
I really do appreciate your help. The problem I had encountered was that the Dataflex database system
used 00/00/0000 as the Base Date. And that the database engine stored that number in Hex in the original
(DOS based) file system. I could find and extract the numbers, but, I could not find out exactly how the data was being
converted to a meaningful date. I am learning to have a lot more respect for people that write database converters now!
james
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:Oa******** ******@TK2MSFTN GP14.phx.gbl...
James,
Use DateTime.AddDay s to find a date given the number of days since a "well known" date. Or to go the other direction use
DateTime.Subtra ct to find the number of days since a "well known" date.

The "problem" you are going to have is that Datetime.MinDat e is 01/01/0001 as opposed to 00/00/0000, I would simply add or
subtract the difference in days as needed...

You may want to consider a pair of functions, something like:

Private Const BaseDate As DateTime = #1/1/1900#
Private Const BaseDays As Integer = 36525

Public Function ToFileDateTime( ByVal value As DateTime) As Integer
Dim ts As TimeSpan = value.Date.Subt ract(BaseDate)
Return CInt(ts.TotalDa ys) + BaseDays
End Function

Public Function FromFileDateTim e(ByVal days As Integer) As DateTime
Return BaseDate.AddDay s(days - BaseDays)
End Function

Where BaseDate & BaseDays are your "well known" date.

Of course if you need dates pre 01/01/0001 then you may have a problem...

Hope this helps
Jay

"james" <jjames700ReMoV eMe at earthlink dot net> wrote in message news:ed******** ******@TK2MSFTN GP11.phx.gbl...
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old
database file that has the date(s) stored in it as number of days.
An example is: 36,525 represents 01/01/1900. The starting point date is considered to be :
00/00/0000. I have looked thru Help and used Google and have not really found an answer.
I know that Leap Years need to be accounted for too.
Any suggestions on where to start ?
james


Nov 21 '05 #4
Thank you for the link Cor. I got Jay's functions working and they seem to do the trick. But, I will investigate the method you
suggest too.
james

"Cor Ligthert" <no************ @planet.nl> wrote in message news:e2******** ******@TK2MSFTN GP11.phx.gbl...
James,

Never done, however I think I would first bring it back to the date in ticks at 00:00:00 hour and than use the normal datetime
format.

http://msdn.microsoft.com/library/de...tickstopic.asp

I hope this helps something

Cor

Nov 21 '05 #5
James,

I real doubt it, althouhg not in Jays solution however.

Dim dd As New DateTime(1799, 12, 31)
dd = dd.AddDays(3652 5)
MessageBox.Show (dd.ToString)
= 01 januari 1900

:-)

Cor
Nov 21 '05 #6
Cor,
Remember James wants from date 00/00/0000 not time 00:00:00.

If James format is Date only (as his post suggests) I don't really see how
Ticks are going to help much, as 0 ticks is date 01/01/0001. To get to
00/00/0000 you might need a negative (or even an imaginary) Tick value,
DateTime will not allow a negative Tick value! Plus how many ticks are there
between 00/00/0000 & 01/01/0001? For that matter how many licks does it take
to get to the center of a tootsie pop?

If James format is really a Date/Time, then Ticks may be of help.
It would seem that 00/00/0000 might be in the same realm as the square root
of negative one!
Question for James: I'm curious What date do you have when you add 1 day to
00/00/0000? What date do you have when you add 1 month? Is year 0000 a Leap
Year? a Leap Century?

Based on the two functions I gave, it would seem that James's "00/00/0000"
date is really 12/31/1799.

In which case James could simplify the functions I gave earlier to:

Private Const BaseDate As DateTime = #12/31/1799#

Public Function ToFileDateTime( ByVal value As DateTime) As Integer
Dim ts As TimeSpan = value.Date.Subt ract(BaseDate)
Return CInt(ts.TotalDa ys)
End Function

Public Function FromFileDateTim e(ByVal days As Integer) As DateTime
Return BaseDate.AddDay s(days)
End Function

Which might be easier to follow, as you are simply finding the number of
days between the two dates...

Now my concern on James' function is Y2K, was it originally coded to account
for the various leap years, centuries & what have you? By my routine
12/31/2005 is 74905? What does James' original code consider 12/31/2005 to
be??

Hope this helps
Jay
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:e2******** ******@TK2MSFTN GP11.phx.gbl...
James,

Never done, however I think I would first bring it back to the date in
ticks at 00:00:00 hour and than use the normal datetime format.

http://msdn.microsoft.com/library/de...tickstopic.asp

I hope this helps something

Cor

Nov 21 '05 #7
Cor,
Reading my other post & your post I suspect the "Real" base date is 1/1/1800
(and not 12/31/1799 as we both found) and the original routine has a Y2K
problem :-)

Which may mean that current dates may be off by 2 days :-(

Just a thought
Jay

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
James,

I real doubt it, althouhg not in Jays solution however.

Dim dd As New DateTime(1799, 12, 31)
dd = dd.AddDays(3652 5)
MessageBox.Show (dd.ToString)
= 01 januari 1900

:-)

Cor

Nov 21 '05 #8
James,

Forget this one, something told me that there was something wrong and
afterwards everybody can see of course 36525/365 = 100 years so 00-00-01 +
100 years is not 1900

See my solution after your message too Jay's

(I was also triggered by the maximum of the timespan, I never checked it,
now I did, I had the idea that Jay had often told in this newsgroup that it
is limited, but it is enough for the solution from Jay).

Cor
Nov 21 '05 #9
Jay,

Afterwards I saw that this was much to much work, I made and sent my last
message before I readed yours. Unlucky not in time to save you the time
making this message, however thanks for the attention.

:-)

Cor
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5207
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much appreciated. TIA
38
7125
by: | last post by:
I have a script... ----- <SCRIPT language="JavaScript" type="text/javascript"> <!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this = makeArray.arguments; } function makeArray0() {
5
14883
by: BlackFireNova | last post by:
I need to write a report in which one part shows a count of how many total records fall within the working days (Monday - Friday) inside of a (prompted) given date range, in a particular geographical region. I have written a query which prompts the user for the start and end dates. It also filters for entries which pertain to the particular...
5
60044
by: Kiran | last post by:
Hi, Please help on date functions in C#. I would like to know the relevant exampl to retrieve 2 weeks before date from the current date, 1 month before date from the current date and number of days. 2 months before date from the current date and number of days. 3 months before date from the current date and number of days. 8 months...
9
2411
by: mistral | last post by:
Need help to remove list of days from date script. Need format "June 07, 2006" <SCRIPT LANGUAGE="JavaScript"> <!-- Begin // Get today's current date. var now = new Date();
4
15711
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow which calculated the difference in years and days between two dates, and takes leap years into account? I'm calculating the difference in the usual...
7
3345
by: No bother | last post by:
I have a table which has, among other fields, a date field. I want to get a count of records where certain criteria are met for, say, three days in a row. For example: NumWidgets Date 1 1/1/2000 10 1/2/2000 20 1/3/2000 10 1/4/2000 15 1/5/2000
2
11355
by: mshroom12 | last post by:
I am having trouble with the following project on hand. I use Eclipse to do my work in Java. This is what I'm supposed to complete. Date Validation In this exercise you will write a program that checks to see if a date entered by the user is a valid date in the second millenium. A skeleton of the program is in Dates.java. Open this program...
7
4148
by: kr151080 | last post by:
Ok so I am messing around with a program and have no idea how to go about doing this but here is the code for the class date.... public class Date { private int dMonth; private int dDay; private in dYear; public Date() {
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.