0

I'm new to SQL. I made an SQL query, but I do not know a correct date format that I wish to use. I have syntax errors, that I can't show right now. Thanks very much for any assistance.

const getWhere = () => {
  const whereCondition = `"Report"."statusId" IN (${statusIds})
  ${params.startDate ? `AND "Report"."createdAt" >= DATE(${moment(params.startDate).format('YYYY-MM-DD')})` : ''}
  ${params.endDate ? `AND "Report"."createdAt" <= DATE(${moment(params.endDate).format('YYYY-MM-DD')})` : ''}`
  return whereCondition;
}
2
  • Tag your question properly that community can find it. It looks like Javascript to me, so I will add a temprorary tag. Commented Mar 31, 2020 at 19:52
  • Also you should add expected date format. From the code you've posted it is not clear of what you are trying to achive. Commented Mar 31, 2020 at 19:57

1 Answer 1

1

The ISO format (YYYY-MM-DD) is fine.

But the date literal must be a string, that is, surrounded by single quotes (').

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.