最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I set Date object to null in Javascript? - Stack Overflow

programmeradmin1浏览0评论

I am trying to set check_date to null I tried

new Date as 0, null


but none of them are working for me. How can I achieve this?

Code

  async lastDayToLive() {
        const allDiner  = await this.amazon.findAll({ where: { flight: 'L' } });
        const len = allDiner .length;
        const lastDinker = allDiner [len - 1];
        const { a,} = lastDinker;
        await this.amazon.update(
            { flight: 'land', check_date: `${new Date(0)}` }, --------------------> Here
            { where: {a}}
        );

        
    }

I am trying to set check_date to null I tried

new Date as 0, null


but none of them are working for me. How can I achieve this?

Code

  async lastDayToLive() {
        const allDiner  = await this.amazon.findAll({ where: { flight: 'L' } });
        const len = allDiner .length;
        const lastDinker = allDiner [len - 1];
        const { a,} = lastDinker;
        await this.amazon.update(
            { flight: 'land', check_date: `${new Date(0)}` }, --------------------> Here
            { where: {a}}
        );

        
    }
Share Improve this question edited Mar 4, 2021 at 18:03 Paritosh M asked Mar 4, 2021 at 17:21 Paritosh MParitosh M 3792 gold badges6 silver badges19 bronze badges 3
  • 2 How is this not working: check_date: null? – codemonkey Commented Mar 4, 2021 at 17:26
  • 1 But do you mean by "not working"? Do you mean whatever you pass that object to is not doing what it's supposed to? Because check_date: null will set check_date to null, no question about it. – codemonkey Commented Mar 4, 2021 at 17:28
  • The issue is clearly not here: { flight: 'land', check_date: null }. It's somewhere up the pipeline. – codemonkey Commented Mar 4, 2021 at 17:49
Add a ment  | 

1 Answer 1

Reset to default 4

You can't set a Date to null. Date is an an embedded JavaScript type.

Setting date to new Date(0) just sets it to Unix Epoch.

You can, however, set a variable to null.

This should work:

var check_date = null;

or, in your case:

        await this.amazon.update(
            { flight: 'land', check_date: null }, 
            { where: {a}}
        );
发布评论

评论列表(0)

  1. 暂无评论