Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date Arango:生成日期序列_Date_Sequence_Arangodb - Fatal编程技术网

Date Arango:生成日期序列

Date Arango:生成日期序列,date,sequence,arangodb,Date,Sequence,Arangodb,有没有办法用日期作为键? 如何生成从特定日期到当前日期的日期 我需要这样的结构: date: "2009-01-01", processing-status: "1" data: "MyData" // current date var now = new Date("2015-08-03 23:59:59Z"); // start date var start = new Date("2015-07-23Z"); var dt = start; // loop until we ha

有没有办法用日期作为键? 如何生成从特定日期到当前日期的日期

我需要这样的结构:

date: "2009-01-01",
processing-status: "1"
data: "MyData"
// current date
var now = new Date("2015-08-03 23:59:59Z"); 
// start date
var start = new Date("2015-07-23Z"); 

var dt = start; 
// loop until we have reached the end date
while (dt.getTime() <= now.getTime()) { 
  // insert document into collection using date from sequence
  db.dates.insert({ date: dt.toISOString().substr(0, 10) }); 
  dt = new Date(dt.getTime() + 86400 * 1000); 
};


我不完全清楚问题是什么,但我会试试看

首先,您需要在
date
属性上设置一个具有唯一索引的集合:

var db = require("org/arangodb").db; 
db._create("dates"); 
db.dates.ensureUniqueConstraint("date"); 
之后,可以使用以下生成器序列插入日期:

date: "2009-01-01",
processing-status: "1"
data: "MyData"
// current date
var now = new Date("2015-08-03 23:59:59Z"); 
// start date
var start = new Date("2015-07-23Z"); 

var dt = start; 
// loop until we have reached the end date
while (dt.getTime() <= now.getTime()) { 
  // insert document into collection using date from sequence
  db.dates.insert({ date: dt.toISOString().substr(0, 10) }); 
  dt = new Date(dt.getTime() + 86400 * 1000); 
};
而不是

db.dates.ensureUniqueConstraint("date"); 

您可以使用AQL创建每个文档都有一个日期属性,范围也在开始日期和结束日期之间:

LET ms_per_day = 1000 * 60 * 60 * 24
LET date_start = DATE_TIMESTAMP(2014, 12, 24)
LET date_end = DATE_TIMESTAMP(2014, 12, 31) // or DATE_NOW()
LET date_diff_in_days = (date_end - date_start) / ms_per_day

FOR val IN 0..date_diff_in_days
    LET date = SUBSTRING(DATE_ISO8601(val * ms_per_day + date_start), 0, 10)
    INSERT {
        "date": date,
        "processing-status": val % 3,
        "data": CONCAT("My Data ", val % 3 + 1)
    } INTO demo
RETURN UNSET(NEW, "_rev", "_key") # debug output