Re: Date from Number of Days

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 02/01/05


Date: Tue, 1 Feb 2005 10:29:36 -0600

James,
My understanding of BCD is that each hex digit (nibble) is its decimal
digit.

http://www.webopedia.com/TERM/B/BCD.html

A byte that contains &H83 is bcd for 83 decimal.

A byte that contains &H01 is bcd for 1 decimal.

A byte that contains &H73 is bcd for 73 decimal.

What I'm not sure about is what if anything they do with the sign (I would
not expect a date to have a sign).

Now when you have a sequence of bytes, endian makes a difference (which end
of the sequence is most significant). My initial test was taking the first
byte as most significant (&H83), it may be that the last byte (&H73) is most
significant. In both cases the numbers seem way too large or way too small
for the conversion you gave earlier.

I'm curious on how Dataflex actually encodes their BCD.

Hope this helps
Jay

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message
news:uyXufICCFHA.3940@TK2MSFTNGP09.phx.gbl...
> Thanks for the ideas Jay. One quick question. As I mentioned in my
> previous post, the Dataflex developers all state that the database engine
> converts the date to number of days then to BCD before storing it in the
> database. Could that be the reason for the Hex values being so far off ?
> It seems to me that they are doing more .
> <pause in thinking>
>
> I just tried something, I took the Hex Values like:
> 830173 ( 83 01 73) and divided them by 365 and all of the values come out
> to: 2274.4465753424657534246575342466 ( 02/08/1999)
> OR
> 2274.526027397260273972602739726
> for Hex value: 83 02 02 ( 03/09/1999)
> OR
> 2280.0356164383561643835616438356
> for Hex value ( 83 22 13) (09/09/2004)
>
> I doubt if that is significant , but, it did seem kind of odd.
> I will continue to work with the suggestions you have provided Jay and
> will let you know what progress, if any, I make.
> Thanks again for all your help.
> james
>
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:etoM49ACFHA.2380@tk2msftngp13.phx.gbl...
>> james,
>> I would start by using the routine to convert the date into the days #
>> (from the earlier post).
>>
>> Then I would compare those values to the ones you list.
>>
>> Unfortunately I don't see anything that is even close, in the bytes you
>> give.
>>
>> Which means that my routine may be "off"... (the Base Date or Base Days
>> constants).
>>
>> Looking at the numbers you give:
>>
>>> 02/10/1998 --82 98 10
>>> 04/21/1998 -- 82 98 80
>>
>> There are 70 days between these two dates, there is a difference of 70
>> between the 3rd byte, this would suggest the 3rd is the least significant
>> digit. I would then expect the first byte to be the most significant
>> digit (by examining the entire column).
>>
>>> 04/21/1998 -- 82 98 80
>>> 04/22/1999 --82 98 81
>>
>> Unfortunately these two are not a day apart, instead they are a year
>> apart!
>>
>>
>> Meaning:
>>> 01/08/1999 -- 83 01 73
>> days = 830173
>>> 03/09/1999 --83 02 02
>> days = 830202
>>> 02/10/1998 --82 98 10
>> days = 839110
>>> 04/21/1998 -- 82 98 80
>> days = 829880
>>> 03/19/1999 --83 02 12
>> days = 830212
>>> 04/22/1999 --82 98 81
>> days = 829881
>>> 11/19/1997 --82 97 27
>> days = 829727
>>
<<snip>>



Relevant Pages

  • Re: How to hande SAP BCD numrics in RPGLE
    ... program that connects to a remote Unix SAP server to retrieve cost ... BCD data is just like packed except that there is no sign. ... last digit is the next to last digit, ... the zero digit), you will then have the actual number. ...
    (comp.sys.ibm.as400.misc)
  • Re: 8086 ALP TO CONVERT BCD -HEXA DECIMAL
    ... Maybe I'm following the wrong links, but I don't see any bcd code, except entwined with floating-point code... ... We want to multiply the "result so far" by ten, and add each digit as we process it. ... digit per byte - and "packed bcd" - one digit per nibble. ... or "mov ax, 0", if you must ...
    (comp.lang.asm.x86)
  • Re: 68K/68332 Assembly/Binary Problem
    ... integer values that can't be represented as 64-bit BCD. ... to compute the place-values during conversions. ... digit of each power of ten. ... power-of-ten LUT with successive subtractions. ...
    (alt.lang.asm)
  • Re: Converting decimal to BCD (binary coded decimal)...
    ... > Is there a handy way to convert a decimal value to it's equivalent BCD ... > representation in VB?? ... Hi John, ... Since one byte represents 2 digits, the following works on a 2 digit number ...
    (microsoft.public.vb.general.discussion)
  • Re: lab help
    ... display '. ... it is best to use XOR instead of mov. ... BCD numbers are already coded in hex. ...
    (comp.lang.asm.x86)