I have a picker wheel with columns for month, day and year (birthdate). How can I convert that to an actual date to test against?
look at the os.time() API call: http://docs.coronalabs.com/api/library/os/time.html
You basically put together a table with the values in it and pass it to os.time and it returns a time value to you.
Thanks Rob, sorry for the late reply. I’ve been working with this to see if I could figure it out though using your idea, and seems I’ve already tried that, but I still must be doing something wrong… My code:
local function handleButtonEvent( event ) local phase = event.phase if "ended" == phase then local values = pickerWheel:getValues() local t = { month = values[1].value, day = values[2].value, year = values[3].value } print (t.month) print (t.day) print (t.year) print( os.time( t ) ) -- print date & time as number of seconds
I get this output:
August
17
2013
But then I get an error on the os.time(t) line: ageCheck.lua:79: field ‘month’ missing in date table
What am I doing wrong? Again, I’m trying to allow the user to select their birthdate in order to do an age validation. ie: make sure they’re 21 years old.
Thanks!
My picker wheel returns the following values:
Well that error indicates that month is set to nil most likey.
Your post did not show your picker wheel values. Maybe you should try printing them out before you put them in the table.
If you look again Rob, you will see that I do print them out, and I listed the output in my post above…
Can you produce a sample that I can run with out running your whole project to let me take a look? I verified that if month is nil then you get the error you’re getting. But your output seems to say it’s set.
look at the os.time() API call: http://docs.coronalabs.com/api/library/os/time.html
You basically put together a table with the values in it and pass it to os.time and it returns a time value to you.
Thanks Rob, sorry for the late reply. I’ve been working with this to see if I could figure it out though using your idea, and seems I’ve already tried that, but I still must be doing something wrong… My code:
local function handleButtonEvent( event ) local phase = event.phase if "ended" == phase then local values = pickerWheel:getValues() local t = { month = values[1].value, day = values[2].value, year = values[3].value } print (t.month) print (t.day) print (t.year) print( os.time( t ) ) -- print date & time as number of seconds
I get this output:
August
17
2013
But then I get an error on the os.time(t) line: ageCheck.lua:79: field ‘month’ missing in date table
What am I doing wrong? Again, I’m trying to allow the user to select their birthdate in order to do an age validation. ie: make sure they’re 21 years old.
Thanks!
My picker wheel returns the following values:
Well that error indicates that month is set to nil most likey.
Your post did not show your picker wheel values. Maybe you should try printing them out before you put them in the table.
If you look again Rob, you will see that I do print them out, and I listed the output in my post above…
Can you produce a sample that I can run with out running your whole project to let me take a look? I verified that if month is nil then you get the error you’re getting. But your output seems to say it’s set.