How about using Julian dates?
Code:
#include <windows.h>
#include <stdio.h>
LONG CalcDays(int iYear, int iMonth, int iDay)
{
LONG lReturnDays = iDay;
int iTemp1 = (14 - iMonth) / 12;
int iTemp2 = iYear + 4800 - iTemp1;
int iTemp3 = iMonth + 12 * iTemp1 - 3;
lReturnDays += (153 * iTemp3 + 2)/5;
lReturnDays += 365 * iTemp2 + iTemp2 / 4 - 32083;
return lReturnDays;
}
BOOL CalcFileAge(char * szFile)
{
LONG lFileDays, lCurrentDays;
FILETIME ftCreate, ftAccess, ftWrite, ftLocal;
SYSTEMTIME stCreate, stNow;
HANDLE hFile;
hFile = CreateFile(szFile,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
{
CloseHandle(hFile);
return FALSE;
}
if (!FileTimeToLocalFileTime(&ftWrite, &ftLocal))
{
CloseHandle(hFile);
return FALSE;
}
GetSystemTime(&stNow);
FileTimeToSystemTime(&ftLocal, &stCreate);
CloseHandle(hFile);
lFileDays = CalcDays(stCreate.wYear,stCreate.wMonth,stCreate.wDay);
lCurrentDays = CalcDays(stNow.wYear,stNow.wMonth,stNow.wDay);
printf("%s is %ld day(s) old\n", szFile, (lCurrentDays - lFileDays));
return TRUE;
}
int main(int argc, char **argv)
{
CalcFileAge(argv[1]);
return 0;
}