FileTimeToDosDateTime

 

Description

converts a 64-bit file time to MS-DOS date and time values

Syntax

BOOL FileTimeToDosDateTime( const FILETIME * lpFileTime, WORD * lpFatDate, WORD * lpFatTime )

Parameters

lpFileTime
[input] File time
lpFatDate
[output]Pointer to a variable to receive the MS-DOS date. The date is a packed 16-bit value with the following format.
Bits Contents
0-4 Day of the month (1-31)
5-8 Month (1 = January, 2 = February, and so on)
9-15 Year offset from 1980 (add 1980 to get actual year)
lpFatTime
[output] Pointer to a variable to receive the MS-DOS time. The time is a packed 16-bit value with the following format.
Bits Contents
0-4 Second divided by 2
5-10 Minute (0-59)
11-15 Hour (0-23 on a 24-hour clock)

Return

If the function succeeds, the return value is true; else return false.

Examples

EX1

int FileTimeToDosDateTime_ex1()
{    
    string                        strFile = "c:\\myfile.txt";
    if(!strFile.IsFile())
    {
        HANDLE hFile = CreateFile(strFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hFile != INVALID_HANDLE_VALUE)
        {
            CloseHandle(hFile);
        }
    }
    
    WORD            FatDate;
    WORD            FatTime;
    FILETIME         localFiletime;    
    WIN32_FILE_ATTRIBUTE_DATA    fileInfo;    
    
    if(!GetFileAttributesEx(strFile, 0, &fileInfo))
    {
        return 0;
    }
    
    FileTimeToLocalFileTime(&fileInfo.ftLastWriteTime, &localFiletime);    
    FileTimeToDosDateTime(&localFiletime, &FatDate, &FatTime);

    int nYear = ((FatDate/512)& 255) +1980 ;    //9-15  bits
    int nMonth = (FatDate/32) & 15;                //5-8   bits
    int nDay = FatDate & 31;                    //0-4   bits
    
    FILETIME        FileTime;
    DosDateTimeToFileTime(FatDate, FatTime, &FileTime);    
    ASSERT(0 == CompareFileTime(&FileTime, &localFiletime) );
    
    FILETIME    ToFileTime;
    if( LocalFileTimeToFileTime(&fileInfo.ftLastAccessTime,&ToFileTime) )
    {
        ASSERT( 0 != ToFileTime.dwLowDateTime );
        ASSERT( 0 != ToFileTime.dwHighDateTime );
    }    
    return 1;
}

Remark

See Also

DosDateTimeToFileTime

header to Include

origin.h

Reference