{"id":108808,"date":"2023-09-21T07:00:00","date_gmt":"2023-09-21T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=108808"},"modified":"2023-09-21T08:41:52","modified_gmt":"2023-09-21T15:41:52","slug":"20230921-00-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20230921-00\/?p=108808","title":{"rendered":"How does Explorer calculate the &#8220;Date&#8221; of a file?"},"content":{"rendered":"<p>Windows File Explorer has a column called &#8220;Date&#8221;. Not &#8220;Date created&#8221; or &#8220;Date modified&#8221;. Just &#8220;Date&#8221;. What is &#8220;Date&#8221;?<\/p>\n<p>The &#8220;Date&#8221; 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.<\/p>\n<p>Note that this table is not contractual. If you are looking to get this Date value programmatically, keep reading.<\/p>\n<table class=\"cp3\" style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Kind<\/th>\n<th>Example<\/th>\n<th>Primary<\/th>\n<th>Secondary<\/th>\n<th>Tertiary<\/th>\n<\/tr>\n<tr>\n<td>Music<\/td>\n<td>.mp3<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-dateacquired\">DateAcquired<\/a><\/td>\n<td>&nbsp;<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-media-dateencoded\">DateEncoded<\/a><\/td>\n<\/tr>\n<tr>\n<td>Picture<\/td>\n<td>.jpg<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-photo-datetaken\">DateTaken<\/a><\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Document<\/td>\n<td>.pdf<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-document-datesaved\">DateSaved<\/a><\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-datemodified\">DateModified<\/a><\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Movie<\/td>\n<td>(?)<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-dateacquired\">DateAcquired<\/a><\/td>\n<td>&nbsp;<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-media-dateencoded\">DateEncoded<\/a><\/td>\n<\/tr>\n<tr>\n<td>Recorded TV<\/td>\n<td>.dvr-ms<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-recordedtv-originalbroadcastdate\">OriginalBroadcastDate<\/a><\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-media-datereleased\">DateReleased<\/a><\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-media-dateencoded\">DateEncoded<\/a><\/td>\n<\/tr>\n<tr>\n<td>Video<\/td>\n<td>.mp4<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-media-datereleased\">DateReleased<\/a><\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-media-dateencoded\">DateEncoded<\/a><\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-dateacquired\">DateAcquired<\/a><\/td>\n<\/tr>\n<tr>\n<td>Email<\/td>\n<td>.eml<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-message-datereceived\">DateReceived<\/a><\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-message-datesent\">DateSent<\/a><\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Contact<\/td>\n<td>.vcf<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-datemodified\">DateModified<\/a><\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-datecreated\">DateCreated<\/a><\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Calendar<\/td>\n<td>.ics<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-startdate\">StartDate<\/a><\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Task<\/td>\n<td>(?)<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-startdate\">StartDate<\/a><\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>Folder<\/td>\n<td>&nbsp;<\/td>\n<td><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-datecreated\">DateCreated<\/a><\/td>\n<td>&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Some of the file extensions are given as question marks because Windows doesn&#8217;t come with any built-in declarations for those kinds, but <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/building-property-handlers-user-friendly-kind-names\"> applications can register new extensions for specific kinds<\/a>, and it&#8217;s possible that you&#8217;ve installed a program that does say &#8220;Oh, yeah, my files are movies.&#8221;<\/p>\n<p>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 <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-datecreated\">DateCreated<\/a> or <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-datemodified\">DateModified<\/a>.<\/p>\n<p>If you want to get this value programmatically, then the thing <i>not<\/i> 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.<\/p>\n<p>Instead, use the shell data model and query <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/properties\/props-system-itemdate\"> the <code>System.ItemDate<\/code> property<\/a>, also known as <code>PKEY_ItemDate<\/code>. Here&#8217;s a sample. Note that all error checking has been elided for simplicity of exposition.<\/p>\n<pre>void PrintFileDate(PCWSTR fullPath)\r\n{\r\n    CComPtr&lt;IShellItem2&gt; item2;\r\n    SHCreateItemFromParsingName(fullPath, nullptr, IID_PPV_ARGS(&amp;item2));\r\n    FILETIME ft{};\r\n    item-&gt;GetFileTime(PKEY_ItemDate, &amp;ft);\r\n    wchar_t buffer[256];\r\n    SHFormatDateTimeW(&amp;ft, nullptr, buffer, 256);\r\n    wprintf(\"%ls\\n\", buffer);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Mapping the generic concept to specific file types.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25,104],"class_list":["post-108808","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code","tag-tipssupport"],"acf":[],"blog_post_summary":"<p>Mapping the generic concept to specific file types.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/108808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=108808"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/108808\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=108808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=108808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=108808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}