Find creation date of datastore key

I saved data in a datastore and I wanted to get the created date of a certain key (example: 10/28/2023). Only problem is, I can’t seem to find a way to get the creation date of the key. I have looked all around the internet to find a solution but I couldn’t.

If anyone can help, that’d be much appreciated! : )

This is provided in the DataStoreKeyInfo object as CreatedTime. It’s a UNIX timestamp that represents, in milliseconds, the time that the key was created. You can parse this time via DateTime.fromUnixTimestampMillis. You get a DataStoreKeyInfo object when you perform a DataStore get request (e.g. GetAsync, UpdateAsync).

local value, keyInfo = DataStore:GetAsync("foobar")

To get the specific format you want, you may be looking at something like this:

local createdTime = DateTime.fromUnixTimestampMillis(keyInfo.CreatedTime)
createdTime:FormatUniversalTime("L", "en-us") --> MM/DD/YY

I’ve noticed that DataStoreKeyInfo works with OrderedDataStores and GlobalDataStores but would it work with regular DataStores, and if it does, how exactly would I go about getting the KeyInfo?

GlobalDataStore is the superclass of all DataStore instances. Both OrderedDataStores and DataStores inherit the base query methods (e.g. GetAsync, SetAsync) from GlobalDataStore.

There are no methods that get GlobalDataStore; GetOrderedDataStore returns an OrderedDataStore instance and GetDataStore returns a DataStore. See my previous post for details.

From the sounds of it, I would have to use GlobalDataStores instead of regular DataStores. If that’s the case, then that would be really bad because I already saved a lot of data with regular DataStores.

Oop- I just read what you originally said again and I understand now! I just tried it and it works. Thank you for helping! :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.