date_to_timestamp
Convert date strings to Unix timestamps for programming and data processing. Supports ISO 8601 and common date formats like '2024-01-15T10:30:00Z' or 'January 15, 2024'.
Instructions
Convert a date string to a Unix timestamp. Accepts ISO 8601 and common date formats.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | Date string (e.g., '2024-01-15T10:30:00Z', '2024-01-15', 'January 15, 2024') |
Implementation Reference
- src/tools/converters.ts:70-95 (handler)The handler implementation for date_to_timestamp that parses a date and returns Unix timestamps and ISO string.
async ({ date }) => { const parsed = new Date(date); if (isNaN(parsed.getTime())) { return { content: [ { type: "text" as const, text: "Error: Could not parse date string. Try ISO 8601 format: 'YYYY-MM-DDTHH:mm:ssZ'.", }, ], isError: true, }; } const result = { unix_seconds: Math.floor(parsed.getTime() / 1000), unix_milliseconds: parsed.getTime(), iso: parsed.toISOString(), }; return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2) }, ], }; } - src/tools/converters.ts:59-95 (registration)The registration of the date_to_timestamp tool in the MCP server.
// Date to Unix timestamp server.tool( "date_to_timestamp", "Convert a date string to a Unix timestamp. Accepts ISO 8601 and common date formats.", { date: z .string() .describe( "Date string (e.g., '2024-01-15T10:30:00Z', '2024-01-15', 'January 15, 2024')" ), }, async ({ date }) => { const parsed = new Date(date); if (isNaN(parsed.getTime())) { return { content: [ { type: "text" as const, text: "Error: Could not parse date string. Try ISO 8601 format: 'YYYY-MM-DDTHH:mm:ssZ'.", }, ], isError: true, }; } const result = { unix_seconds: Math.floor(parsed.getTime() / 1000), unix_milliseconds: parsed.getTime(), iso: parsed.toISOString(), }; return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2) }, ], }; }