How do I Convert DateTime to a Number?

Title says it all. Here is my code incase your wondering:

local DateUploaded = DateTime.fromIsoDate(ProductInfo.Created)
		
if (tonumber(DateUploaded) < FirstItemDate) then -- FirstItemDate is a number
	-- Continue code.
end

Error:

attempt to compare nil < number

Essentially, I need to convert the DateTime retrieved from DateTime.fromIsoDate(ProductInfo.Created) into a number so I can compare the two Unix timestamps.

1 Like

Try

local DateUploaded = DateTime.fromIsoDate(ProductInfo.Created).UnixTimestamp

Not too familiar with DateTime as a data type

1 Like

DateTime is of type table, and it cannot be simply put through tonumber. For DateTime, you can use the “UnixTimestamp” property of the class. Example:

local DateUploaded = DateTime.fromIsoDate(ProductInfo.Created)

if DateUploaded.UnixTimestamp < FirstItemDate then
    -- Continue code.
end
2 Likes

Thank you @ElusiveEpix and @popgoesme700, this worked!