javascriptdateobjectnull

How can I set Date object to null in Javascript?


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}}
        );

        
    }

Solution

  • 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}}
            );