sijocherian / google-bigquery

Automatically exported from code.google.com/p/google-bigquery
0 stars 0 forks source link

Please add date truncate feature for timestamps #231

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please add a date truncate feature for timestamps that is similar to the Oracle 
database trunc() function:

http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions201.htm

and 

http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions230.htm#i1002084

Original issue reported on code.google.com by mgr...@zulily.com on 2 Apr 2015 at 4:25

GoogleCodeExporter commented 9 years ago
Thanks for the suggestion.

Right now you can use UTC_USEC_TO_{HOUR,DAY,WEEK,MONTH,YEAR}, which does 
effectively the same thing for numeric time values. For example, to truncate to 
the nearest month, you can write:

  USEC_TO_TIMESTAMP(UTC_USEC_TO_MONTH(TIMESTAMP_TO_USEC(timestamp)))

I know it's clumsy that you have to convert back and forth from timestamps, but 
I think this will do what you want.

Original comment by jcon...@google.com on 2 Apr 2015 at 5:03