我被困在下面: 我可以得到date_diff的子部分,但不能一起。 任何帮助表示赞赏。
SQL Server :
SELECT (DATEADD(DD, DATEDIFF(dd, 0, GETDATE()), 0))
Big Query :
SELECT DATETIME_ADD(CURRENT_DATETIME(), INTERVAL DATE_DIFF(CURRENT_DATE, DATE '1900-01-01', DAY))
答案 0 :(得分:1)
您可以使用此SQL作为示例
#standardSQL
SELECT DATE_DIFF(DATE(CURRENT_DATETIME()), DATE_ADD(DATE(CURRENT_DATETIME()) ,INTERVAL 3 DAY), DAY),INTERVAL 3 DAY), DAY)
FROM `project.dataset.table`
答案 1 :(得分:0)
Without a clear understanding of the use case, I'm going just to correct the query:
DAY
for DATETIME_ADD
function.DATE_ADD
function if you do not need time.So, this query is working as expected:
#standardSQL
SELECT DATETIME_ADD(CURRENT_DATETIME(), INTERVAL DATE_DIFF(CURRENT_DATE, DATE '1900-01-01', DAY) DAY) as result_datetime,
DATE_ADD(CURRENT_DATE, INTERVAL DATE_DIFF(CURRENT_DATE, DATE '1900-01-01', DAY) DAY) as result_date