Change System.DateModified format on Windows Search

夙愿已清 提交于 2019-12-02 07:11:17

问题


I'm using Windows Indexing search together with PHP to search inside thousands of files.

I got it working by using the PHP COM class:

$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$recordset = new COM("ADODB.Recordset");

$conn - > Open("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';");


$recordset - > Open("SELECT System.ItemName, System.DateModified FROM  SYSTEMINDEX  WHERE DIRECTORY='file:C:/xxxx/' AND CONTAINS('xxxx')", $conn);

$recordset - > MoveFirst();

while (!$recordset - > EOF) {
    echo $recordset - > Fields - > Item("System.ItemName") - > Value."\n";
    $recordset - > MoveNext();
}

I am retrieving the DateModified field of each element and I've realized the format of it depends on the System configuration. It is possible to set it through the control panel in Windows.

I am wondering if there's any way to get it in the desired format in order to avoid having to change it by using the control panel in every system I want to run the script.

I noticed the object has the property formatAs but I'm not sure how to change it and the documentation is not very complete.

Thanks.


回答1:


You can convert a VT_DATE object into a UNIX timestamp with variant_date_to_timestamp and then format it with date, this should work regardless of the date format in the control panel.

$format = "Y-m-d";
$object = $recordset->Fields->Item("System.DateModified")->Value;
$timestamp = variant_date_to_timestamp($object);
echo date($format, $timestamp) . "\n";


来源:https://stackoverflow.com/questions/21835330/change-system-datemodified-format-on-windows-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!