I have an issue where a date value is used to send to an application for some processing that needs to first be formatted to a different DateTime format.
What I have
I start with a DateTime value in the format of:
MM/DD/YYYY hh:mm:ss [AM/PM]
What I need
Somehow with Lua I need to transform this into the DateTime format of:
YYYY-MM-DD hh:mm:ss
I've had no luck with many various things I've tried; I'll post the thing I tried I feel may be most appropriate but maybe this is way off too and there's an easier or more simple LUA method.
What I tried
print(os.date("%Y-%m-%d %H:%M:%S","05/17/2017 05:17:00 PM"))
Error
stdin:1: bad argument #2 to 'date'(number expected, got string)
What I'm assuming
I think this means the data type is a string rather than a datetime type and it'll need to convert it before os.date can use it. I'm also assuming I can pass the value of the datetime string I have to os.date and it will output this same datetime value wise but in the new format I need instead.
I've read various posts about needing to parse out the parts of the datetime value and then using those parsed out portions to build the format you need. I'm posting in hopes someone can help steer me in the proper direction with this task so I don't have to go thru a ton more trial and error runs and do a ton more reading but I'll be doing that until I hear back or give up for the day.
Simple Recap
I start with a value of:
05/17/2017 05:17:00 PMI would like to get this value to
2017-05-17 17:17:00
With the newly formatted datetime, I can then do something with it for the application to process.
Other
Any level of Lua logic to resolve this will be explored whether it be a custom function, different built-in functions to get the datetime formatted, etc. I'm open to all ideas and just showed the print() and os.date() functions in my example to keep it simple but I'm open to something more complex.