Paradox Date field to human readable format

  • Thread starter Thread starter mphanke
  • Start date Start date
M

mphanke

Hi,

can somebody tell me how to convert the date from a Paradox .DB to human
readable format?

I need to write a tool to convert the 4 Bytes representing the date to a
human readable format.

Thanks for your help,

Martin
 
Use the DateTime constructor which takes a long (Int64) as parameter.
Iam not sure wheather the date is the higher or the lower 32 bits but you
can try it.
 
Martin,

Are you using a Data Provider for the DB? If so, then the provider
should be responsible for changing it into a DateTime (assuming the column
is analagous to it).

If not, what are you using to get at the database?
 
Hi,

since the application is to be installed on very old computers, I'm
bound to not using .NET . I'm reading the header and then parsing the file.

They are using some freaky representation of days since 1/1/1 (some type
of Julian date, but not really!) the dates I have are 1/1/100 which
corresponds to 36.160 and 5/4/1996 which is 728.783.

I just don't get how they are coding this stuff!?!?

Martin
 
Hi,

thanks to everybody for the support. I figured out how to do this stuff.
It's a bit tricky but this snippet should do the conversion:

(- {BTW I know it is ugly coding =;-P}
This code is provided as is and comes with no guaranty what so ever!
Feel free to avoid the pain I had by using this snippet.
-)

Thanks,

Martin

int isLeap(int year)
{
return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400)==0));
}

void ConvertDate(long days, int &day, int &month, int &year)
{
long _days;
int yearlengths[] = {365,366};
int length[2][12];

length[1][0] = length[0][0] = 31;
length[0][1] = 28;
length[1][1] = 29;
length[1][2] = length[0][2] = 31;
length[1][3] = length[0][3] = 30;
length[1][4] = length[0][4] = 31;
length[1][5] = length[0][5] = 30;
length[1][6] = length[0][6] = 31;
length[1][7] = length[0][7] = 31;
length[1][8] = length[0][8] = 30;
length[1][9] = length[0][9] = 31;
length[1][10] = length[0][10] = 30;
length[1][11] = length[0][11] = 31;

_days = days & 0x7fffffff ;
_days--;
year = 1;

int *len;
int leap = 0;

while(_days<0 || _days >= yearlengths[leap = isLeap(year)])
{
int nyear = year + _days/365;

if(_days < 0)
{
nyear--;
}

_days -= (nyear - year)*365 + ((nyear-1)/4 - (nyear-1)/100 +
(nyear-1)/400) -
((year-1)/4 - (year-1)/100 + (year-1)/400);
year = nyear;
}

len = length[leap];

for(month = 0; _days >= len[month]; month++)
{
_days -= len[month];
}

month++;

_days++;

day = _days;
}
 
Back
Top