To convert timestamp to date you can use the BigQuery date / time functions :
SELECT TIMESTAMP(1424184621000000)
To calculate the number of days between two dates (for example, between 6/1/15 and 6/20/15), you can do this:
SELECT (DATEDIFF(TIMESTAMP('2015-06-20'), TIMESTAMP('2015-06-01')) + 1)
And finally, you can use the following to calculate business days:
SELECT (DATEDIFF(TIMESTAMP('2015-06-20'), TIMESTAMP('2015-06-01')) + 1) -(INTEGER((DATEDIFF(TIMESTAMP('2015-06-20'), TIMESTAMP('2015-06-01')) + 1) / 7) * 2) -(CASE WHEN DAYOFWEEK(TIMESTAMP('2015-06-01')) = 1 THEN 1 ELSE 0 END) -(CASE WHEN DAYOFWEEK(TIMESTAMP('2015-06-20')) = 7 THEN 1 ELSE 0 END)
This is a simple calculation of working days taking into account Saturdays and Sundays as weekends and without any holidays.
Qorbani
source share