I know how to get this from today’s date but if I have a date such as 12/4/2016 how would I get the month name and weekday name?
Thanks,
Warren
I know how to get this from today’s date but if I have a date such as 12/4/2016 how would I get the month name and weekday name?
Thanks,
Warren
Step 1 - Split the date into parts:
(https://roaminggamer.github.io/RGDocs/pages/SSK2/extensions/#string)
local date = "12/4/2016" local parts = string.split( date, "/" ) -- SSK2 string.\* Extension print( parts[1], parts[2], parts[3] ) -- Prints: 12 4 2016
Step 2 (Convert To Time) - Use os.time() to convert the prior data into time coded as a number
https://www.lua.org/pil/22.1.html
local encoded = os.time( { day = tonumber(parts[2]), month = tonumber(parts[1]), year = tonumber(parts[3]) } ) print( encoded ) -- Prints: 1480881600
Step 3 (Convert To Date) - Use os.date() to convert the encoded time to any kind of date format you want:
https://www.lua.org/pil/22.1.html
local weekday = os.date("%A",encoded) local month = os.date("%B",encoded) print( weekday, month) -- prints: Sunday December
Here it is all together:
-- Assuming this is MM/DD/YYYY -- -- Personal Note: I hate civilian dates for this very reason: Ambiguous and easy to forget. -- local date = "12/4/2016" local parts = string.split( date, "/" ) print( parts[1], parts[2], parts[3] ) -- Prints: 12 4 2016 local encoded = os.time( { day = tonumber(parts[2]), month = tonumber(parts[1]), year = tonumber(parts[3]) } ) print( encoded ) local weekday = os.date("%A",encoded) local month = os.date("%B",encoded) print( weekday, month)
Thanks but I realized I have to buy the lib to have the split function?
I found a LUA split function to use. Thanks!!!
I do like your lib and going through it right now also.
Step 1 - Split the date into parts:
(https://roaminggamer.github.io/RGDocs/pages/SSK2/extensions/#string)
local date = "12/4/2016" local parts = string.split( date, "/" ) -- SSK2 string.\* Extension print( parts[1], parts[2], parts[3] ) -- Prints: 12 4 2016
Step 2 (Convert To Time) - Use os.time() to convert the prior data into time coded as a number
https://www.lua.org/pil/22.1.html
local encoded = os.time( { day = tonumber(parts[2]), month = tonumber(parts[1]), year = tonumber(parts[3]) } ) print( encoded ) -- Prints: 1480881600
Step 3 (Convert To Date) - Use os.date() to convert the encoded time to any kind of date format you want:
https://www.lua.org/pil/22.1.html
local weekday = os.date("%A",encoded) local month = os.date("%B",encoded) print( weekday, month) -- prints: Sunday December
Here it is all together:
-- Assuming this is MM/DD/YYYY -- -- Personal Note: I hate civilian dates for this very reason: Ambiguous and easy to forget. -- local date = "12/4/2016" local parts = string.split( date, "/" ) print( parts[1], parts[2], parts[3] ) -- Prints: 12 4 2016 local encoded = os.time( { day = tonumber(parts[2]), month = tonumber(parts[1]), year = tonumber(parts[3]) } ) print( encoded ) local weekday = os.date("%A",encoded) local month = os.date("%B",encoded) print( weekday, month)
Thanks but I realized I have to buy the lib to have the split function?
I found a LUA split function to use. Thanks!!!
I do like your lib and going through it right now also.