# Fields: Date & Time

> Part of the NocoDB documentation (Workflows > Scripts > Examples > Generic). Index of all pages: https://nocodb.com/llms.txt. Any docs page is available as Markdown by adding `.md` to its URL.

URL: https://nocodb.com/docs/workflows/scripts/examples/demo/field-date-time
Last updated: 2026-10-03

A NocoDB script that creates Date, Time, DateTime and Duration fields.

This script shows how to create and use these fields in NocoDB:
`Date` `Time` `DateTime` `Duration`

For details on each field type and its configuration options, refer to the [NocoDB meta API documentation](https://nocodb.com/apis/v3/meta#tag/Fields).

```javascript
// NocoDB Script: Create Date & Time Fields

const tableName = 'DateTime Fields Demo';
let table = base.getTable(tableName);

if (!table) {
  table = await base.createTableAsync(tableName, []);
  output.text(`✅ Created table: "${tableName}"`);
}

async function createField(name, config) {
  if (!table.getField(name)) {
    await table.createFieldAsync({ name, ...config });
    output.text(`✅ Created: ${name}`);
  }
}

// Date field
//
await createField('Start Date', {
  type: "Date",
  default_value: "2025-01-01", // ISO date format
  description: "The starting date of the event or task",
  options: {
      date_format: "YYYY-MM-DD"
  }
});

// Time field
//
await createField('Start Time', {
  type: "Time",
  default_value: "09:00", // 24-hr format
  description: "The starting time of the event or task",
  options: {
      "12hr_format": true // Use 12-hour format with AM/PM
  }
});

// DateTime field
//
await createField('Due DateTime', {
  type: "DateTime",
  default_value: "2025-01-01T17:00", // ISO datetime format
  description: "Deadline including both date and time"
});

// Duration field
//
await createField('Duration (mins)', {
  type: "Duration",
  default_value: "300", // in seconds
  description: "Expected duration of the event or task in minutes",
  options: {
      duration_format: "h:mm"
  }
});

output.table(table.fields.map(f => ({ 'Field Name': f.name, 'Type': f.type })));
output.text(`ℹ️ Total fields created: ${table.fields.length}`);

```

---

## Related pages

- [Table Operations](https://nocodb.com/docs/workflows/scripts/examples/demo/table-operations.md): A NocoDB script that checks if a table exists, creates a table and lists all tables in the base.
- [Fields: Text-Based](https://nocodb.com/docs/workflows/scripts/examples/demo/field-text-based.md): A NocoDB script that creates and manages text-based fields.
- [Fields: Numerical](https://nocodb.com/docs/workflows/scripts/examples/demo/field-number-based.md): A NocoDB script that creates numerical fields for quantities, percentages, currency and more.
- [Fields: Select](https://nocodb.com/docs/workflows/scripts/examples/demo/field-select-based.md): A NocoDB script that creates single select and multi select fields to categorize data.
- [Fields: System](https://nocodb.com/docs/workflows/scripts/examples/demo/field-system.md): A NocoDB script that creates system fields to capture audit information automatically.
- [Fields: User & Collaborator](https://nocodb.com/docs/workflows/scripts/examples/demo/field-user.md): A NocoDB script that creates a User field to assign or reference users in records.
- [Fields: Virtual & Formula](https://nocodb.com/docs/workflows/scripts/examples/demo/field-virtual.md): A NocoDB script that adds calculated or derived data with virtual fields.
- [Fields: Miscellaneous](https://nocodb.com/docs/workflows/scripts/examples/demo/field-miscellaneous.md): A NocoDB script that creates fields for attachments, checkboxes, ratings and structured data.
