How does Explorer calculate the “Date” of a file?

Raymond Chen

Windows File Explorer has a column called “Date”. Not “Date created” or “Date modified”. Just “Date”. What is “Date”?

The “Date” is what Explorer thinks is the most relevant date for the item in question. And what determines that relevance depends on what kind of file it is.

Note that this table is not contractual. If you are looking to get this Date value programmatically, keep reading.

Kind Example Primary Secondary Tertiary
Music .mp3 DateAcquired   DateEncoded
Picture .jpg DateTaken    
Document .pdf DateSaved DateModified  
Movie (?) DateAcquired   DateEncoded
Recorded TV .dvr-ms OriginalBroadcastDate DateReleased DateEncoded
Video .mp4 DateReleased DateEncoded DateAcquired
Email .eml DateReceived DateSent  
Contact .vcf DateModified DateCreated  
Calendar .ics StartDate    
Task (?) StartDate    
Folder   DateCreated    

Some of the file extensions are given as question marks because Windows doesn’t come with any built-in declarations for those kinds, but applications can register new extensions for specific kinds, and it’s possible that you’ve installed a program that does say “Oh, yeah, my files are movies.”

The system first looks for a value associated with the primary property. If no value is found, then it looks for the secondary. If still not found, then it looks for the tertiary. If nothing works, then system chooses the earlier of the DateCreated or DateModified.

If you want to get this value programmatically, then the thing not to do is to try to replicate the above table, because the details of that table can change as the shell team decides to tweak its heuristics.

Instead, use the shell data model and query the System.ItemDate property, also known as PKEY_ItemDate. Here’s a sample. Note that all error checking has been elided for simplicity of exposition.

void PrintFileDate(PCWSTR fullPath)
{
    CComPtr<IShellItem2> item2;
    SHCreateItemFromParsingName(fullPath, nullptr, IID_PPV_ARGS(&item2));
    FILETIME ft{};
    item->GetFileTime(PKEY_ItemDate, &ft);
    wchar_t buffer[256];
    SHFormatDateTimeW(&ft, nullptr, buffer, 256);
    wprintf("%ls\n", buffer);
}

9 comments

Discussion is closed. Login to edit/delete existing comments.

  • Simon Mourier 0

    And that explains why displaying “Date” in a newly opened Shell folder can take so long if it contains video files for example, it’s because the Shell (or maybe some 3rd party extensions) goes spelunking into the item’s metadata to determine the “Date”. If you un-choose that “Date” column and choose DateModified instead, everything is faster, but maybe makes less sense 🙂

  • Sigge Mannen 1

    Who would be interested in anything other than Date Modified. Nice with some shell stuff, i missed the “real” win32 articles 🙂

    • skSdnW 0

      For TV and pictures, the date from metadata makes more sense than some minor modification to the file or media container.

      DateAcquired I don’t agree with however. I care a lot more about when a song was released, not when I purchased it. MSDN says “For example, this data is used as the main sorting axis for the virtual folder New Music, which enables people to browse the latest additions to their collection.” which makes sense for such a specific folder but not for files in generic folders.

      • Mystery Man 1

        DateAcquired I don’t agree with however. I care a lot more about when a song was released, not when I purchased it.

        Most songs don’t have it. Music metadata and MP4 format provision for a Year field but no app puts a year, month, day, hour, minute, second, and millisecond in there. Imagine looking at your music and thinking, “Gee, why do these musicians always release on the midnight of the first of January?”

        • skSdnW 0

          Some tag with the full ISO date. Either way, the point is to sort roughly by release date, especially when dealing with a single artist.

  • Henke37 0

    Of course, the real question is how you programmatically ask which underlying property the shell picked this time.

    • Raymond ChenMicrosoft employee 1

      If you care, then don’t use PKEY_ItemDate. Use one of the explicit dates. The purpose of PKEY_ItemDate is “Give me a date that is most likely to match what the user considers to be the date of the thing.”

  • Gunnar Dalsnes 0

    Why not DateReleased for mp3?

  • Johan Hanson 0

    How is this presented to the user?

    It would be nice if there was a tooltip that explained what kind of date it is when you hover the mouse pointer over it.

    Also, if all files in a folder are the same kind, the column name could reflect that.

Feedback usabilla icon