简体   繁体   中英

Date Diff in calculated field

I am trying to create a computed column to display the number of days between now and a date in another field. I have tried the following:

DATEDIFF(d, @Now(), [NextServiceDate])

But I get the following error:

'Assets' table - Error validating the formula for column 'DaysTillService'.

I have tried without the @ but I get the same error.

也许您应该尝试getdate()

DaysTileService as (DATEDIFF(day, getdate(), NextServiceDate))

@Now() is invalid. It is a mixture of a variable name (prefix @ ) and a function ( () ).

Try this:

DECLARE @Now DATETIME = GETDATE()

and change your code to:

DATEDIFF(d, @Now, [NextServiceDate])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM