Date from Number of Days

  • Thread starter Thread starter james
  • Start date Start date
Jay, here is another post I copied that I think contains a clue to the whole thing!!


"create a file containing these statements:

set_date_attribute sysdate4_State to DFTRUE // sysdate returns 4 digit
year
set_date_attribute date4_State to DFTRUE // 2-digit year entries are
automatically converted to 4-digit
set_date_attribute epoch_value to 80 // Year 0 to 80 add 2000, Year
81 to 99 add 1900

Include it in all of your programs, recompile and your problem should be
gone. "


I just know there is a clue in the above statement!! But, then again..........I could just be grasping at straws!!
james
 
Jay, FINALLY a response from a Dataflex developer that makes some sense and gives good info on the dates. Here is a copy of a
response to my post of Data Access's Newsgroup:

___________________________________________________________

James - I think you'll find that the dates are really just integers (AKA
Julian Dates). Any DF programmer who did Y2K work knows the infamous
693975. That's the value for 01/01/1900. Now - you'll also have to test to
make sure all dates are 4 year or 2 year. If 2 year, add the 693975 to' em,
then they'll be 4 year.

So - you've got a bunch of integers, now what? Since this is going to
Access, you could use VB:
--------------
Dim StartingDate as Date, BuildDate as Date, IntValue as Integer,
DFDateValue as Single
StartingDate=DateValue(1900,01,01) 'I think I have the syntax/command
right here - check it!!

'fill DFDateValue with the value from the DF database

IntValue=DFDateValue - 693975 'this will get it down to integer size for
VB

'maybe do some error checking to see if it's > zero

BuildDate = DateAdd(StartingDate,"d",IntValue) 'I think I have the syntax
right here - check it!!

'set the db date to BuildDate
--------------

Please note that my VB may be rusty - so try this at your own risk!

Don't know if this'll work for you - but maybe it's a starting point.

Garret
_____________________________________________________________

The fact that the system is using Julian Dates leads to a better understanding of what is going on.
What do you think Jay ?
james
 
James,
I'm still not seeing any nice dates come out...

What I'm curious about is given your three bytes, how do you get the
DFDateValue value?

The 693975 appears to be an alternate BaseDate constant.

Looking at your original data:
01/08/1999 -- 83 01 73
03/09/1999 --83 02 02
02/10/1998 --82 98 10
04/21/1998 -- 82 98 80
03/19/1999 --83 02 12
04/22/1999 --82 98 81
11/19/1997 --82 97 27

It almost appears that the 2nd byte is the year, but its not consistent: I
wonder if its something odd like 2nd, 1st, 3rd...

Hope this helps
Jay
 
Jay, here is what I have managed to get going so far, but, it still gives wrong dates.
Private Sub btnJulian_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnJulian.Click


Dim StartingDate As Date

Dim BuildDate As Date

Dim IntValue As Integer

Dim DFDateValue As Single

DFDateValue = 832213 'should be 09/09/2004

StartingDate = DateValue("1900, 1, 1")

IntValue = DFDateValue - 693975

BuildDate = DateAdd(DateInterval.Day, IntValue, StartingDate)

TextBox2.Text = BuildDate.ToString

End Sub



Instead of getting : 09/09/2004 I get this with the above code: 6/26/2278 12:00:00 AM

I think this is because the Integer values are for Julian Dates and VB.NET is not interacting correctly with it. Especially ,
since I used the DateInterval.Day.

Well, still, it is more information than I started out with.

james
 
James,

That was my latest result as well however than I looked at the differences
in your dates (I started with the first 3 and after a while I recongized you
wrote it in US dates and it was even more crazy). That should be easy to get
the trick. However I did not see the key too that. It is of course something
simple and than oh.

Cor
 
James,
I was seeing dates in that range (2278) also.
I think this is because the Integer values are for Julian Dates and
VB.NET is not interacting correctly with it. Especially , since I used
the DateInterval.Day.
DFDateValue = 832213 'should be 09/09/2004

Are you certain that 832213 should be 9/9/2004?

I would expect 732212 to be 9/9/2004,
as there are 39237 days between 1/1/1900 & 9/9/2004
39237 + 693975 = 732212.

Interesting 100001 days off...

If you use:

Private Const BaseDate As DateTime = #1/1/1900#
Private Const BaseDays2 As Integer = 693975

Public Function ToFileDateTime(ByVal value As DateTime) As Integer
Dim ts As TimeSpan = value.Date.Subtract(BaseDate)
Return CInt(ts.TotalDays) + BaseDays2
End Function

Public Function FromFileDateTime(ByVal days As Integer) As DateTime
Return BaseDate.AddDays(days - BaseDays2)
End Function

Dim theBytes As String = "82 97 27"
Dim theDays As Integer = CInt(theBytes.Replace(" ", "")) - 100001
Dim theDate = FromFileDateTime(theDays)

You get 11/19/1997 as expected.

In fact given your initial column of data, they all match expect 1/8/1999 =
83 01 73

I would probably move the 100001 adjustment into the two routines...

Hope this helps
Jay
 
Doha!
In fact given your initial column of data, they all match expect 1/8/1999
= 83 01 73

Just noticed a couple were off:

82 97 27: expected=11/19/1997, calculated=11/19/1997
82 98 10: expected=2/10/1998, calculated=2/10/1998
82 98 80: expected=4/21/1998, calculated=4/21/1998
83 01 73: expected=1/8/1999, calculated=2/8/1999 *
83 02 02: expected=3/9/1999, calculated=3/9/1999
83 02 12: expected=3/19/1999, calculated=3/19/1999
82 98 81: expected=4/22/1999, calculated=4/22/1998 *

Hope this helps
Jay
 
<now , were is that little icon with the blushing face?> Huh? OH! I'm typing a response to Jay!!!
How about:

83 01 73: expected = 02/08/1999
82 98 81: expected= 04/22/1998

I admit it, I made a couple of typing errors in my original post when I listed those dates and Values!!
I should have reread my list before now!
Dang Jay, you are good at this stuff!
james

<ducks head>
 
Jay, thank you for the code. It really works. I have been testing it with several "correct" values :-) and it works good. I will
work it into my file reader and see how well it handles things on the fly.
james
 
Back
Top