Daily Coding Challenge - Mongo ID Date

Tell us what’s happening:

I’m confused on how this script isn’t passing the test cases. I’m retrieving the first 8 characters from the hex string using the .substring() method, so that I can then convert it to a decimal via the .parseInt() method with a radix of 16 (so that it can handle hex). I then use the Date() constructor followed by the toISOString() method to put it in the ISO 8601 string format

Your code so far

function mongoIdToDate(id) {
  const subString = id.substring(0, 8);
  const decimalValue = parseInt(subString, 16);
  const dateValue = new Date(decimalValue);

  id = dateValue.toISOString();

  return id;
}

console.log(mongoIdToDate("6a094b50bcf86cd799439011"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36

Challenge Information:

Daily Coding Challenge - Mongo ID Date

https://www.freecodecamp.org/learn/daily-coding-challenge/2026-05-17

you may want to check what unit of measure new Date needs, you are returning "1970-01-21T14:09:54.000Z

The first 8 characters represent a Unix timestamp (in seconds)

is new Date accepting a value in seconds?

Ah, thank you for the clarification! I went ahead and converted the decimal value (time in seconds) to a decimal value that represents the time in milliseconds in order to meet the proper format for the Date constructor.