Skip to content
Advertisement

I need to group by year and month from a timestamp structured as yyyyMMddHHmmss 20170227141500

I need to group by year and month from a timestamp, structured as yyyyMMddHHmmss 20170227141500 (Google’s bigquery gkg table). I need to count the year monthly records. Data type is integer. timestamp is the column name. In fact, I need to gruop by first 6 digits of the timestamp. yearmonth is my group name, not included in the table.

Advertisement

Answer

It is a number so you cannot use date/time functionality. You can convert to a string and take the leftmost 6 characters:

You should fix the data to store date/time values as either datetimes or timestamps.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement