skip to Main Content

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

2

Answers


  1. 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('');
    }
    
    Login or Signup to reply.
  2. 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()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search