進度:
1.我從收集中退出日期。 示例格式:五月05日14:59:31 +0000 2012
2.我能夠更改其格式。使用PHP進行日期轉換和更新mongodb文檔使用PHP
代碼中使用:
$cur=$col->find(array(),array("created_at"=>1,"_id"=>0));
// created_at = contains Date value
$cur_all=$col->find();
while($doc=$cur_all->getNext())
{
$doc2=$cur->getNext();
$pieces = implode(" ", $doc2);
//converted the array to string with space delimiting
if($pieces!=NULL)
{
$date1 = date_create_from_format("D M d G:i:s +O Y", $pieces);
echo date_format ($date1 , 'Y-m-d G:i:s');
//This is the format i would like to update in mongodb..
$filter = array('_id'=>new MongoId($doc['_id']));
$update = array('$set'=>array('created_at'=> newMongoDate($date2)));
$col->update($filter,$update);
}
}
問題:
在哪裏創建一個日期對象,以便它可以在收集預期的格式更新到文件? (格式:Y-m-d G:i:s)
P.S:我在Stackoverflow上做了很多研究(還有其他地方),但我無法得出任何結論。這就是爲什麼這個問題。讓我知道,如果有任何澄清
關於我的問題的清晰真對不起創建日期。它類似於1.從mongodb(格式:D M d G:i:s + O Y)獲取現有日期。2.將其更改爲新格式(Y-m-d G:i:s)。 3.更新mongodb中的更改。 – 2013-03-18 07:26:31
@SethuSabarish Yea MongoDB不能,除非你使用一個字符串或者其他的東西(我不會)以這種格式存儲,它只能以你的代碼格式顯示 – Sammaye 2013-03-18 08:02:46
::目前,我把日期保存在字符串中格式。感謝您的幫助。 – 2013-03-21 07:50:56