Skip to main content
Glama

get_elapsed_time

Calculate time duration between two datetime values in specified units like milliseconds, hours, or days for precise interval measurement.

Instructions

Get the difference time between two datetimes (e.g. 2025-01-01 01:01:01 and 2025-01-02 02:02:02)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromYes
toYes
unitNomillisecond

Implementation Reference

  • Handler function that calculates the elapsed time between two datetimes using dayjs.diff, with validation for valid dates.
    async ({ from, to, unit = "second" }) => { const fromDateTime = dayjs(from); const toDateTime = dayjs(to); if (!fromDateTime.isValid() || !toDateTime.isValid()) { return { content: [{ type: "text", text: "Invalid format" }], isError: true, }; } /** * {@link https://day.js.org/docs/en/display/difference} */ const duration = toDateTime.diff(fromDateTime, unit, true); return { content: [{ type: "text", text: String(duration) }], }; },
  • Input schema using Zod for the from datetime, to datetime, and optional unit (defaults to millisecond).
    { from: z.string(), to: z.string(), unit: z .enum([ "millisecond", "second", "minute", "hour", "day", "week", "month", "year", ]) .optional() .default("millisecond"), },
  • src/index.ts:131-168 (registration)
    Registration of the get_elapsed_time tool using server.tool, including description, input schema, and inline handler.
    server.tool( "get_elapsed_time", "Get the difference time between two datetimes (e.g. 2025-01-01 01:01:01 and 2025-01-02 02:02:02)", { from: z.string(), to: z.string(), unit: z .enum([ "millisecond", "second", "minute", "hour", "day", "week", "month", "year", ]) .optional() .default("millisecond"), }, async ({ from, to, unit = "second" }) => { const fromDateTime = dayjs(from); const toDateTime = dayjs(to); if (!fromDateTime.isValid() || !toDateTime.isValid()) { return { content: [{ type: "text", text: "Invalid format" }], isError: true, }; } /** * {@link https://day.js.org/docs/en/display/difference} */ const duration = toDateTime.diff(fromDateTime, unit, true); return { content: [{ type: "text", text: String(duration) }], }; }, );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/t-shiratori/time-tools-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server