Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Passing through a DATE as NULL - PSQL Query

I have a form that is suppose to take five date values, these dates (in some cases) refer to tasks in the future so it is not always necessary that they have a value. As a result, there are situations where the user may pass in three dates on the add form but leave the other two dates blank. My code was working perfectly so long as the user was entering all five dates but now that some are being left blank I can not get the app to work.

Database - This Query works fine with a null value so I know a date col can be NULL


INSERT INTO applicants (store, first_name, last_name, position, date_in,recruiterscreen_completion,testing_completion,
 interview_completion, backgroundcheck_completion, drugscreen_completion, paperwork_completion) 
VALUES ('Autoexpress','Test','test','Salesperson','2/21/22',NULL,'2/20/22','2/21/22','2/20/22','2/21/22','2/20/22') RETURNING *

Back End Code - However when I pass the value through I get errors

/*ADD NEW APPLICANT REQUEST*/
const addApplicant = async (req, res) => {
  const errors = validationResult(req);

  if (!errors.isEmpty()) {
    return res.status(400).json({ errors: errors.array() });
  }

  const { store, first_name, last_name, position, recruiterscreen_completion,testing_completion,backgroundcheck_completion,interview_completion,drugscreen_completion,paperwork_completion, date_in } = req.body;

  try {
  console.log(recruiterscreen_completion)
    const applicants = await queryInstance(`INSERT INTO applicants (store, first_name,last_name,position, recruiterscreen_completion,testing_completion,backgroundcheck_completion,interview_completion,drugscreen_completion,paperwork_completion, date_in) VALUES ('${store}', '${first_name}', '${last_name}', '${position}', '${recruiterscreen_completion}', '${testing_completion}', '${backgroundcheck_completion}','${interview_completion}','${drugscreen_completion}','${paperwork_completion}','${date_in}') RETURNING *`);
    res.json({ applicants });
  } catch (err) {
    console.error(err.message);
    return res.status(500).send(err.message);
  }
}; 

Add Form (Example of one of the form elements)

<label className="add-form-label-long" htmlFor="recruiterscreen_completion">
          Recrutier Screen
          <input
            type="date"
            id="recruiterscreen_completion"
            name="recruiterscreen_completion"
            onChange={handleFormChange}
            value={formData.recruiterscreen_completion}
          ></input>
        </label>

If the user does not select any date in the dropdown does a NULL value pass through? Or is it undefined? How do I resolve?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!