Skip to main content

Datetime Value Methods

Datetime fields are handled as strings in Studio SDK responses. The returned format is YYYY-MM-DD HH:mm:ss.

Assignment​

await context.form.update({
recordId: 'record-id',
data: {
submitted_at: '2026-06-18 10:30:00',
},
});

Accepted input examples:

InputNormalized Value
'2026-06-18 10:30:00''2026-06-18 10:30:00'
new Date()format before writing
nullclear the field when allowed

Convert To Timestamp​

const datetimeText = String(record.data.submitted_at || '');
const timestamp = new Date(datetimeText.replace(' ', 'T')).getTime();

if (Number.isNaN(timestamp)) {
throw new Error('SUBMITTED_AT_INVALID');
}

Convert To Date​

const datetimeText = String(record.data.submitted_at || '');
const dateText = datetimeText.split(' ')[0] || '';
const timeText = datetimeText.split(' ')[1] || '';

Format From Date​

function formatDatetime(value: Date) {
const date = [
value.getFullYear(),
String(value.getMonth() + 1).padStart(2, '0'),
String(value.getDate()).padStart(2, '0'),
].join('-');
const time = [
String(value.getHours()).padStart(2, '0'),
String(value.getMinutes()).padStart(2, '0'),
String(value.getSeconds()).padStart(2, '0'),
].join(':');

return `${date} ${time}`;
}