Hi all,
i'm working on a converter (Borland Paradox to CSV/DBF) and have a problem. I need to convert the 4 Bytes representing the date but
it's a weird representation of days since 1/1/1 :
for example :
$B0805 = 02/06/1980 (dd/mm/yyyy)
$B26B9 = 20/11/2001
$B2AC4 = 20/09/2004
I found some codes (VC++ !?) but can't translate.
Can somebody help me with this ?
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;
}
Need Help with Borland's Paradox (DOS) Date Format
-
Bonne_den_kule
- Addict

- Posts: 841
- Joined: Mon Jun 07, 2004 7:10 pm
First one:
Rest of the code is some multidimensonal array thing.
Cant help you more, dosent know c++, only javascript(same syntax)
Code: Select all
Procedure.l isLeap(year.l)
If year%4=0 And year%100<>0 Or year%400=0
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedureRest of the code is some multidimensonal array thing.
Cant help you more, dosent know c++, only javascript(same syntax)
Thanks Bdk
i found something interesting :
---------------
Gregorian Dates
---------------
What is a leap year?
A leap year is a year with one extra day inserted into February, the leap year is 366 days with 29 days in February as opposed to the normal 28 days.
Which years are leap years?
In the Gregorian calendar, which is the calendar used by most modern countries, the following rules decides which years are leap years:
Every year divisible by 4 is a leap year. But every year divisible by 100 is NOT a leap year unless the year is also divisible by 400, then it is still a leap year. This means that year 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years, while year 2000 and 2400 are leap years.
i found something interesting :
---------------
Gregorian Dates
---------------
What is a leap year?
A leap year is a year with one extra day inserted into February, the leap year is 366 days with 29 days in February as opposed to the normal 28 days.
Which years are leap years?
In the Gregorian calendar, which is the calendar used by most modern countries, the following rules decides which years are leap years:
Every year divisible by 4 is a leap year. But every year divisible by 100 is NOT a leap year unless the year is also divisible by 400, then it is still a leap year. This means that year 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years, while year 2000 and 2400 are leap years.
I have what i needed !
Thank you for your help.
Procedure.s GregorianDateToString(Date.l)
If Date.l < $8D40 : Date.l = $8D40 : EndIf ;Min. value (01/01/0100)
If Date.l > $37B9DB : Date.l = $37B9DB : EndIf ;Max. value (31/12/9999)
Day = 0
Month = 1
Year = 100
LeapYear = 0
For counter = 36160 To Date.l
Day = Day + 1
If Month = 1 Or Month = 3 Or Month = 5 Or Month = 7 Or Month = 8 Or Month = 10 Or Month = 12
If Day = 32
Day = 1
Month = Month + 1
If Month = 13
Month = 1
Year = Year + 1
LeapYear = 0
If Year % 4 = 0 : LeapYear = 1 : EndIf
If Year % 100 = 0 : LeapYear = 0 :EndIf
If Year % 400 = 0 : LeapYear = 1 : EndIf
EndIf
EndIf
ElseIf Month = 2
If Day = 29 + LeapYear
Day = 1
Month = Month + 1
If Month = 13
Month = 1
Year = Year + 1
LeapYear = 0
If Year % 4 = 0 : LeapYear = 1 : EndIf
If Year % 100 = 0 : LeapYear = 0 :EndIf
If Year % 400 = 0 : LeapYear = 1 : EndIf
EndIf
EndIf
Else
If Day = 31
Day = 1
Month = Month + 1
If Month = 13
Month = 1
Year = Year + 1
LeapYear = 0
If Year % 4 = 0 : LeapYear = 1 : EndIf
If Year % 100 = 0 : LeapYear = 0 :EndIf
If Year % 400 = 0 : LeapYear = 1 : EndIf
EndIf
EndIf
EndIf
Next
ProcedureReturn Str(Day) + "/"+Str(Month) + "/" + Str(Year)
EndProcedure
Debug GregorianDateToString($B2B9A)
Thank you for your help.
Procedure.s GregorianDateToString(Date.l)
If Date.l < $8D40 : Date.l = $8D40 : EndIf ;Min. value (01/01/0100)
If Date.l > $37B9DB : Date.l = $37B9DB : EndIf ;Max. value (31/12/9999)
Day = 0
Month = 1
Year = 100
LeapYear = 0
For counter = 36160 To Date.l
Day = Day + 1
If Month = 1 Or Month = 3 Or Month = 5 Or Month = 7 Or Month = 8 Or Month = 10 Or Month = 12
If Day = 32
Day = 1
Month = Month + 1
If Month = 13
Month = 1
Year = Year + 1
LeapYear = 0
If Year % 4 = 0 : LeapYear = 1 : EndIf
If Year % 100 = 0 : LeapYear = 0 :EndIf
If Year % 400 = 0 : LeapYear = 1 : EndIf
EndIf
EndIf
ElseIf Month = 2
If Day = 29 + LeapYear
Day = 1
Month = Month + 1
If Month = 13
Month = 1
Year = Year + 1
LeapYear = 0
If Year % 4 = 0 : LeapYear = 1 : EndIf
If Year % 100 = 0 : LeapYear = 0 :EndIf
If Year % 400 = 0 : LeapYear = 1 : EndIf
EndIf
EndIf
Else
If Day = 31
Day = 1
Month = Month + 1
If Month = 13
Month = 1
Year = Year + 1
LeapYear = 0
If Year % 4 = 0 : LeapYear = 1 : EndIf
If Year % 100 = 0 : LeapYear = 0 :EndIf
If Year % 400 = 0 : LeapYear = 1 : EndIf
EndIf
EndIf
EndIf
Next
ProcedureReturn Str(Day) + "/"+Str(Month) + "/" + Str(Year)
EndProcedure
Debug GregorianDateToString($B2B9A)
