# db.serverDate

Constructs a reference to the server time, used to query a condition, update a field value, or add a record.

The method signature is shown as below:

function serverDate(options?: object): ServerDate

The method accepts an optional object parameter "options", whose field is defined as follows:

Field Type Required Default Description
offset number No The offset of the server time referenced (in ms). It can be positive or negative.

Sample code

When adding a record, set the field as the server time:

const db = wx.cloud.database()
db.collection('todos').add({
  description: 'eat an apple',
  createTime: db.serverDate()
})

Update the field to one hour later than the server time:

const db = wx.cloud.database()
db.collection('todos').doc('my-todo-id').update({
  due: db.serverDate({
    offset: 60 * 60 * 1000
  })
})
``