datetimesurrealdb

SurrealDB: How to add a day, week, month to a datetime?


I need to add "2 weeks" to time::now()'s value.

For example:

-- Now: 2023-07-09T21:48:57.676702494Z
time::now() 

-- Two weeks later than now: 2023-07-21T21:48:57.676702494Z
time::now() + <SOMETHING>

How can I add to a datetime value a week, a day or an hour etc?

Thanks!


Solution

  • 2w is the you're looking for, as shown in the example here: https://surrealdb.com/docs/surrealdb/surrealql/datamodel/datetimes#durations-and-datetimes

    Try:

    return type::datetime(time::now()+2w)