---
id: 69f35a5bb823ed620fcb7cb9
title: "Challenge 280: Mongo ID Date"
challengeType: 29
dashedName: challenge-280
---

# --description--

Given a MongoDB ID string, return its creation time as an ISO 8601 string.

- A MongoDB ID is a 24-character hex string. The first 8 characters represent a Unix timestamp (in seconds) encoded as a base-16 integer.

For example, `"6a094b50bcf86cd799439011"` has a timestamp of `"6a094b50"` in hex, which is `1778994000` in decimal, representing a creation time of `"2026-05-17T05:00:00.000Z"`.

# --hints--

`mongo_id_to_date("6a094b50bcf86cd799439011")` should return `"2026-05-17T05:00:00.000Z"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(mongo_id_to_date("6a094b50bcf86cd799439011"), "2026-05-17T05:00:00.000Z")`)
}})
```

`mongo_id_to_date("695344eb1f4a4c1123042128")` should return `"2025-12-30T03:20:11.000Z"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(mongo_id_to_date("695344eb1f4a4c1123042128"), "2025-12-30T03:20:11.000Z")`)
}})
```

`mongo_id_to_date("386da62df34123ac54617e56")` should return `"2000-01-01T07:01:01.000Z"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(mongo_id_to_date("386da62df34123ac54617e56"), "2000-01-01T07:01:01.000Z")`)
}})
```

`mongo_id_to_date("69f571c3d7711807afd3dd55")` should return `"2026-05-02T03:38:43.000Z"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(mongo_id_to_date("69f571c3d7711807afd3dd55"), "2026-05-02T03:38:43.000Z")`)
}})
```

`mongo_id_to_date("68adce01c0e1144d0a90295a")` should return `"2025-08-26T15:08:49.000Z"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(mongo_id_to_date("68adce01c0e1144d0a90295a"), "2025-08-26T15:08:49.000Z")`)
}})
```

# --seed--

## --seed-contents--

```py
def mongo_id_to_date(s):

    return s
```

# --solutions--

```py
from datetime import datetime, timezone

def mongo_id_to_date(s):
    timestamp = int(s[:8], 16)
    dt = datetime.fromtimestamp(timestamp, tz=timezone.utc)
    return dt.strftime("%Y-%m-%dT%H:%M:%S.000Z")
```
