求助 云开发 数据库查询最近30天记录,查询不到?

发布于 9 年前作者 yong634210 次浏览最后编辑 9 年前来自 issues

我数据库字段createDate 类型为date

const db = wx.cloud.database();

const _ = db.command;

db.collection('t_pin')

.where({ createDate: _.gte(Date('2020-3-1 00:00')) })

.limit(20)

.orderBy('createDate', 'desc')

.get({

success: function (res) {

console.log('aaaaaaaaaaaa',res)

}

})

取到的是空记录,我想取3月1号后的记录,要怎么取啊? 多谢

4 回复
lei55
lei551 楼6 年前

3月1号后的

就是3-1号到现在的

fang12
fang122 楼6 年前

凡是云开发涉及日期的问题,一律建议用绝对时间

pingbai
pingbai3 楼6 年前

duming
duming4 楼6 年前
let start = $.dateFromParts({
      year: 2020,
      month: 3,
      day: 1,
      hour: 0,
      minute: 0,
      second: 0,
      millisecond: 0,
      timezone: 'Asia/Shanghai'
    })

...where(_.expr($.gte(['$createDate', start])))