#Invalid Date format?

1 messages · Page 1 of 1 (latest)

brave dew
#

heres my script:
local HttpService = game:GetService("HttpService")

local apiKey = "5bcec9b848mshb94162050789960p1c6280jsn3ca0120e8036"

local function formatDate(year, month, day)
return string.format("%04d-%02d-%02d", year, month, day)
end

local startYear = 2017
local startMonth = 2
local startDay = 20

local today = os.date("*t")

local yesterday = os.time({
year = today.year,
month = today.month,
day = today.day - 1,
hour = 0,
min = 0,
sec = 0
})

local yesterdayTable = os.date("*t", yesterday)

if yesterdayTable.day == 0 then
yesterdayTable.month = yesterdayTable.month - 1
if yesterdayTable.month == 0 then
yesterdayTable.year = yesterdayTable.year - 1
yesterdayTable.month = 12
end
yesterdayTable.day = os.date("*t", os.time({year = yesterdayTable.year, month = yesterdayTable.month + 1, day = 0})).day
end

local startDate = formatDate(startYear, startMonth, startDay)
local endDate = formatDate(yesterdayTable.year, yesterdayTable.month, yesterdayTable.day)

local apiUrl = "https://cash4life.p.rapidapi.com/History?startDate=" .. startDate .. "&endDate=" .. endDate

local function fetchData()
local headers = {
["X-RapidAPI-Key"] = apiKey,
["X-RapidAPI-Host"] = "cash4life.p.rapidapi.com"
}

local success, result = pcall(function()
    return HttpService:RequestAsync({
        Url = apiUrl,
        Method = "GET",
        Headers = headers
    })
end)

if success then
    local data = HttpService:JSONDecode(result.Body)
    print(data

heres my output im having trouble with:
20:06:27.895 ▼ {
["message"] = "Invalid date! Please enter a date in the format of yyyy-MM-dd",
["status"] = "error"
} - Server - Script:52
20:06:27.895 Total Draws: 0 - Server - Script:61

#

I'm unsure as to what exactly is wrong; hopefully, someone more experienced can help me find the problem.

void linden
#

hide ur api key first of all

#

second its because local today = os.date("t") retursn the number of days in teh cur month, NOT A TABLE

#

so u indexing on balls.

void linden
#
local today = os.date("*t")```
brave dew
# void linden try this

looool, I know I'm not the brightest. It's a public API, so we chillin'. Also, that didn't work; I got the same output :((

void linden
#

u were supposed to fix yesterday also

brave dew
#

ill cry if you dont continue im lost

#

yesterday?

#

OK

#

DUHDUH

#

Noooo, lmao! I am more than willing to praise you, DW, but it didn't work. Here's my code again just to make sure I implemented what you helped me with correctly. -
local HttpService = game:GetService("HttpService")

local apiKey = "5bcec9b848mshb94162050789960p1c6280jsn3ca0120e8036"

local function formatDate(year, month, day)
return string.format("%04d-%02d-%02d", year, month, day)
end

local startYear = 2017
local startMonth = 2
local startDay = 20

local yesterday = os.time() - 86400
local yesterdayTable = os.date("*t", yesterday)

local startDate = formatDate(startYear, startMonth, startDay)
local endDate = formatDate(yesterdayTable.year, yesterdayTable.month, yesterdayTable.day)

local apiUrl = "https://cash4life.p.rapidapi.com/History?startDate=" .. startDate .. "&endDate=" .. endDate

local function fetchData()
local headers = {
["X-RapidAPI-Key"] = apiKey,
["X-RapidAPI-Host"] = "cash4life.p.rapidapi.com"
}

local success, result = pcall(function()
    return HttpService:RequestAsync({
        Url = apiUrl,
        Method = "GET",
        Headers = headers
    })
end)

if success then
    local data = HttpService:JSONDecode(result.Body)
    print(data)
    if data and type(data) == "table" then
        local drawCount = 0
        for _, draw in ipairs(data) do
            print("Winning Numbers:", draw.WinningNumbers)
            print("Drawing Date:", draw.DrawingDate)
            drawCount = drawCount + 1
        end
        print("Total Draws:", drawCount)
    else
        warn("Data is not a table or is nil:", data)
    end
else
    warn("API request failed:", result)
end

end

fetchData()

#

got this in my output same as before but still -
21:07:26.515 ▼ {
["message"] = "Invalid date! Please enter a date in the format of yyyy-MM-dd",
["status"] = "error"
} - Server - Script:37
21:07:26.515 Total Draws: 0 - Server - Script:45

keen helmBOT
#

studio** You are now Level 1! **studio

brave dew
#

I also checked the API, and it does have those dates available, so I'm not exactly sure why it's acting up right now.

#

it says the API can retreive a single day, 10 days, or records back to 02/20/2017

brave dew
#

@void linden , if you're still willing to help, I'm still having trouble. Not tryna spam or anything, you just seem like you know what you're talking about.