In Google Cloud SQL, how can you figure out a date difference?

Associate
Joined
24 Sep 2022
Posts
2
Location
India
I'm attempting to create a query that would show the difference in date between a date recorded in a column and the current date, but I keep receiving the following error:

Code:
"Cannot call method "getTime" of null."

What function can I use to calculate this date difference in Google Cloud SQL?

Current code:

Code:
SELECT date, DATEDIFF(date, CURRENT_DATE()) AS daysLeft
FROM table;
 
* It's `DATE_DIFF`, not `DATEDIFF` (reference: https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#date_diff)
* You need to specify what units to return, usually will be `DAY`.

The rest looks ok in your query, so I'd guess this should work:

Code:
SELECT date, DATE_DIFF(date, CURRENT_DATE(), DAY) AS daysLeft
FROM table;

No idea where `getTime` is coming from, do you have another (sub)query somewhere?
 
Back
Top Bottom