In BigQuery table what I using some date stored in DateTime typed columns with value like "2016-01-20T00:00:00". I want to run query that for example show row which included in some range (lets say from 2016-01-01 to 2016-02-28).
So problem is that when I put
...Where data < TIMESTAMP('2017-01-30 00:00:00')...//less then
it show me nothing but when I change it to opposite value like
...Where data > TIMESTAMP('2017-01-30 00:00:00')...//greater then
it returns me even those values that logically should be excluded (like 2017-01-20)
I have tested that TIMESTAMP('2017-01-20 00:00:00') returning '2017-01-26 00:00:00 UTC'.
So which method from bigQuery DateTime I should use to be able to compare dates that I have? May be I need to convert both of them into some kind 'milliseconds since' value?
Thanks
Try: Date(date_column) between current_date()...
Subtracting a unit Subtracting a specific amount of days, weeks, months, quarters, or years from a date can be done using the DATE_SUB function. The first argument takes a date and the second argument takes an interval, a numeric value, and a unit.
Thank you all for help. Your answers and link has leaded me to solution.
where data<cast('2017-01-23 00:00:00' as datetime)
cast('2017-01-23 00:00:00' as datetime)
provide '2017-01-23T00:00:00'
value and bigQuery are happy with it and give me wanted result.
If your column is of datetime int:
Where data < 20170130
and
Where data > 20170130
If your column is of datetime datatype, drop the TIMESTAMP:
Where data < '2017-01-30 00:00:00'
and
Where data > '2017-01-30 00:00:00'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With