On this page

Date-time field

The date-time field stores a timestamp in milliseconds to represent a date-time value.

Date-time field

Examples

Here's an example of using the date-time field in a block:

# blocks/Product.vue

<template>
  <div>
    <span v-if="!publishDate || Date.now() > publishDate">Available</span>
    <span v-else>Not available</span>
    ...
  </div>
</template>

<script lang="ts" setup>
import { dateTimeField } from '#pruvious'

defineProps({
  publishDate: dateTimeField({
    description: 'The date and time when the product is published or scheduled for publication.',
  }),
})
</script>

Here is another example of how to use it in a collection definition:

# collections/products.ts

import { defineCollection } from '#pruvious'

export default defineCollection({
  name: 'products',
  mode: 'multi',
  fields: {
    releaseDate: {
      type: 'date-date',
      options: {
        description: 'The date and time when the product is published or scheduled for publication.',
      },
    },
    // ...
  },
})

Options

You can specify the following options in the date-time field:

OptionDescription

clearable

A boolean indicating whether to display a clear button that removes the current value.

default

The default field value (null if not defined).

description

A brief descriptive text displayed in code comments and in a tooltip at the upper right corner of the field.

label

The field label displayed in the UI. By default, it is automatically generated based on the property name assigned to the field. For example, eventDate becomes Event date.

max

The latest possible date and time (as timestamp in milliseconds).

min

The earliest possible date and time (as timestamp in milliseconds).

name

A string that specifies the name for the input controls. If not specified, the name attribute will be automatically generated.

placeholder

Text that appears in the input element when it has no value set.

required

Specifies that the field input is mandatory during creation.

utc

A boolean flag indicating whether to use UTC time in the date-time picker. The stored value is always in UTC. The default setting is true.

Last updated on January 6, 2024 at 17:29