Old Timestamp

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
FloSoft

Old Timestamp

Post by FloSoft »

Hi,
i found an old QBasic 3 program of which i have no source. I tried to decode the data-files, but got some problems:

How do I translate an old "timestamp"?

Data in File (Hex) -> Displayed in Program as

A0 94 59 94 -> 10.12.89
E0 95 59 94 -> 30.12.89
60 89 59 94 -> 30.10.89
60 90 43 94 -> 30.10.80
60 F3 71 94 -> 30.10.99
00 53 45 91 -> 30.10.10

Its not a plain integer, (no unix timestamp)
I hope somebody can help me to decode this.
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

You could read them as String of 8 characters (if the periods you displayed here are part of the data) or 6 characters (if the periods are just spaces).

Then you could do the following assuming your field is called DateField:

Code: Select all

DIM DayValue   AS INTEGER
DIM MonthValue AS INTEGER
DIM YearValue  AS INTEGER

DayValue = VAL(LEFT$(DateField, 2))
MonthValue = VAL(MID$(DateField, 3, 2))
YearValue = 1900 + VAL(RIGHT$(DateField, 2))

In the case of the first line of date you should you should then have

DayValue = 10
MonthValue = 12
YearValue = 1989

You can then form a string with this in a function:

Code: Select all

FUNCTION DateString(Day AS INTEGER, Month AS INTEGER, Year AS INTEGER) AS STRING

    DIM DayOffset   AS STRING
    DIM MonthOffset AS STRING
    DIM WorkDate   AS STRING

    IF Day < 10 THEN
       DayOffset="0"
    ELSE
       DayOffset = ""
    END IF

    IF Month < 10 THEN
       MonthOffset="0"
    ELSE
       MonthOffset = ""
    END IF
    DateString$ = DayOffset + TRIM$(STR$(Day)) + "-" + MonthOffset + TRIM$(STR$(Month)) + "-" + TRIM$(STR$(Year))

END FUNCTION
And that will return you a date in the form of "DD-MM-YYYY" which you should be able to use.

Hope this helps
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Re: Old Timestamp

Post by moneo »

FloSoft wrote:Hi,
i found an old QBasic 3 program of which i have no source. I tried to decode the data-files, but got some problems:
How do I translate an old "timestamp"?
Data in File (Hex) -> Displayed in Program as

A0 94 59 94 -> 10.12.89
E0 95 59 94 -> 30.12.89
60 89 59 94 -> 30.10.89
60 90 43 94 -> 30.10.80
60 F3 71 94 -> 30.10.99
00 53 45 91 -> 30.10.10

Its not a plain integer, (no unix timestamp)
I hope somebody can help me to decode this.
I've been looking at the hex values. They don't make sense.

Maybe the hex values represent the number of offset days from some pivot year. Even thinking this, the values still don't make an sense, because if
A0 94 59 94 means 10.12.89, and
E0 95 59 94 means 30.12.89,
then these supposed dates are only 20 days apart, but the hex values
don't reflect a 20 day difference any way you look at them.

Whoever created these hex values had his own kookie algorithm.
I give up.
*****
FloSoft

Post by FloSoft »

@MystikShadows: Hmm the Values are only 4 Bytes.

@mondeo: Yeah that was my problem too. I found following:

Between 30.12.10 und 30.12.11 are exaktly 1280000 "Seconds" in the timestamp (if you interpret the 4 bytes as an 32bit integer) if you divide that value by 3600, you get 355.5555555. But that does not help me much, but perhaps you have another idea?
FloSoft
Newbie
Posts: 1
Joined: Mon Oct 10, 2005 2:59 am
Contact:

Post by FloSoft »

Sorry, i could not edit my previous post:

I currently found another thing:

2488898720 10.12.89
2488898880 20.12.89
2488899040 30.12.89

the first number is the integer if you interpret those 4 bytes as int (little endian, end to front)

if you subtract them from each other, you get:

30.12.89 -> 20.12.89 : 160
20.12.89 -> 10.12.89 : 160
30.12.89 -> 10.12.89 : 320

so one day is interpreted as a value of 16?

[edit]
ok i found out that all values above the year "00" are strange. if i stay between 70-99 it works:

Day: 16
Month: 1600
Year: 160000

10.08.95:

10*16 + 8*1600 + 95* 160000 + 2474639360 (kind of "base"?) = correct timestamp

the other way round works too.

[/edit]
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

Some Ideas:

1.-
The DOS file timestamp uses bitfields,7 bits for the minute, 5 bits for the hour, 6 bits for day, 4 bits for month and the rest for year since 1980 (iirc) . If you think it could be that I can check my old books for the exact format.


2.-
Microsoft Excel uses a floating point value, the unit is one day.
Post Reply