pass a timestamp as a parameter in the query using the node js postgre library (pg)

159 views Asked by At

I'm trying to make a request to the database using the pg library of node js, as you can see in the code below i try to pass a parameter to the query with the date and time, but for some reason it does not return any data, unlike when I execute the same query directly in pgAdmin.

here is my code:

let company_id = req.body.company_id;
let start_date = moment(req.body.startDate).format('YYYY-MM-DD 00:00:00');
let end_date = moment(req.body.endDate).format('YYYY-MM-DD 23:59:59');
        
let query = `
    SELECT count(v.vulnerabilidad_id)
    FROM vulnerabilidad AS v
    INNER JOIN escaneo AS e ON e.id = v.escaneo_id
WHERE
    e.cliente_id = $1
AND
    e.timestamp BETWEEN $2 AND $3;
`;
        
let parameters = [client_id, start_date, end_date];
let response = await pool.query(query, parameters);

As I mentioned before, when formatting the date by adding the time the query stops working and return 0 rows, but if I only send the date without the time, this query does return data

pg version is 7.12.1

I expect too make a query from nodejs where I can pass the date with the time as a parameter

0

There are 0 answers