Skip to main content
Glama

get_elapsed_time

Calculate the elapsed time between two specified datetimes in customizable units (milliseconds to years) for precise duration 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

  • The asynchronous handler function that computes the elapsed time (difference) between 'from' and 'to' datetimes using dayjs.diff, with optional unit. Returns duration as string or error if invalid 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) }], }; },
  • Zod input schema for the tool: 'from' and 'to' as strings (datetimes), 'unit' as optional enum with default '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 on the MCP server, specifying name, description, input schema, and handler function.
    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) }], }; }, );

Other Tools

Related Tools

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