'How do I use the BigQueryDate class in the BigQuery nodejs client library?

I have a BigQuery table with a column of type "DATE". When I query the table with the nodejs client library as per below, the date elements in the data are objects of the BigQueryDate class. The documentation for the BigQueryDate class provides no explanation on how the use the class. I would like to convert the date objects to either JavaScript date objects, or date strings, so I can use the date data in my application.

const { BigQuery } = require("@google-cloud/bigquery");
const bigquery = new BigQuery();
const query = "SELECT * FROM `project.dataset.table`";
bigquery.query(query, function(err, rows) {
  if (!err) {
    console.log(rows);
  }
});


Solution 1:[1]

The only parameter that the class has is value, which is the date as a string of the form yyyy-mm-dd.

const { BigQueryDate } = require("@google-cloud/bigquery");
const date = new BigQueryDate("2019-01-20");
date.value; // returns string "2019-01-20"

Solution 2:[2]

I encountered the same situation and found my answer as below:
I'm assuming that you've executed query and looping through the rows

// Import the Google Cloud client library
const {BigQuery} = require('@google-cloud/bigquery');
...
//connect to BigQuery and get the results
...
//loop through the rows and print it on console.
console.log('Rows:');
rows.forEach(
row => console.log(`${row.Col1}:${row.Col2}:${(row.DateCol3).value}:${row.col4}`)
);

Note: Here DateCol3 is date column in BigQuery dataset.
Hope this helps many others.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Max888
Solution 2 shary.sharath