Re: Date from Number of Days

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: james (jjames700ReMoVeMe)
Date: 01/30/05


Date: Sun, 30 Jan 2005 12:29:12 -0600

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]" <Jay_Harlow_MVP@msn.com> wrote in message news:OaAny1pBFHA.2428@TK2MSFTNGP14.phx.gbl...
> James,
> Use DateTime.AddDays to find a date given the number of days since a "well known" date. Or to go the other direction use
> DateTime.Subtract to find the number of days since a "well known" date.
>
> The "problem" you are going to have is that Datetime.MinDate 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.Subtract(BaseDate)
> Return CInt(ts.TotalDays) + BaseDays
> End Function
>
> Public Function FromFileDateTime(ByVal days As Integer) As DateTime
> Return BaseDate.AddDays(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" <jjames700ReMoVeMe at earthlink dot net> wrote in message news:edEivQoBFHA.3616@TK2MSFTNGP11.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
>>
>>
>
>



Relevant Pages

  • Re: Date from Number of Days
    ... Jay, ... >> James, ... >> Public Function FromFileDateTime(ByVal days As Integer) As DateTime ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Project issues list load time
    ... the whole database. ... Jay, MCP ... > This posting is provided "AS IS" with no warranties, and confers no rights. ... >>> occur with all large Issues lists not just certain ones. ...
    (microsoft.public.sharepoint.teamservices)
  • Re: Codding Questions/Problems
    ... "James" wrote in message ... > On that form it has two boxes one which is a memo field ... > Anything in any table in the database? ... Roger dot Carlson at Spectrum-Health dot Org ...
    (microsoft.public.access.modulesdaovba)
  • Re: Searching Across Multiple Tables
    ... James ... "Ron Weiner" wrote: ... > database design may be flawed, and you are doomed before you start. ... >>> Depending what you what to do with the results of this query there might ...
    (microsoft.public.access.formscoding)
  • Re: Questions - Repost
    ... James ... >Andrew J. Kelly SQL MVP ... You are Following a backup plan for a database. ...
    (microsoft.public.sqlserver.server)