Home > OS >  I need to add current date to firebase Realtime database in react native
I need to add current date to firebase Realtime database in react native

Time:10-23

STATE OF CURRENT DATE

const [date, setDate] = React.useState(new Date())
    console.log('date', date);

DATE CAN'T PUSHED TO FIREBASE DATABASE AND HOW TO PUSH DATE IN REALTIME DATABASE.

 function addNewPerson() {
        push(ref(db, '/addperson'), {
            //   addperson: value,
            //    value,
            'Name': name,
            'Room_no': selectedRoomNo,
            'Contact': contact,
            'Address': address,
            'Image': fetchImage,
            'Advanced_amount': advancedAmount,
            'Date': date,
        });
        // setPresentTodo('');
    }

CodePudding user response:

You can add like below:

function addNewPerson() {
    push(ref(db, '/addperson'), {
        //   addperson: value,
        //    value,
        'Name': name,
        'Room_no': selectedRoomNo,
        'Contact': contact,
        'Address': address,
        'Image': fetchImage,
        'Advanced_amount': advancedAmount,
        'Date': new Date().toUTCString(),
    });
    // setPresentTodo('');
}

CodePudding user response:

new Date() is a function you can't directly store the date function you need to convert it into a string and then it can be stored in the database

new Date().toISOString()
  • Related