Date format in Lua

I am retrieving the date from the database in the following format:

vardate = '01/20/2017 09:20 :35'-mm/dd/yyyy hh:mm:ss

I want to convert it to the format dd-mm-yyyy hh:mm:ss

I can get some information about How can I get guidance in the format I want?

Date formatting in Lua is pretty simplistic. If you only need to convert it from one format to Another format, and the format will not change, you only need to use string.match:

function convertDate(vardate)
local d,m ,y,h,i,s = string.match(vardate,'(%d+)/(%d+)/(%d+) (%d+):(%d+):(%d+)')
return string.format('%s/%s/%s %s:%s:%s', y,m,d,h,i,s)
end

- -Call it this way
convertDate('01/20/2017 09:20:35')

If you need more participation, I recommend using an external library.

I am retrieving the date from the database in the following format:

vardate = '01/20/2017 09:20:35 '-mm/dd/yyyy hh:mm:ss

I want to convert it to the format dd-mm-yyyy hh:mm:ss

I can get some information on how to get Do I want guidance in the format?

Date formatting in Lua is pretty simplistic. If you only need to convert it from one format to another, and the format will not change, You only need to use string.match:

function convertDate(vardate)
local d,m,y,h,i,s = string.match (vardate,'(%d+)/(%d+)/(%d+) (%d+):(%d+):(%d+)')
return string.format('%s/%s/ %s %s:%s:%s', y,m,d,h,i,s)
end

-- Call it this way
convertDate(' 01/20/2017 09:20:35')

If you need more participation, I recommend using an external library.

Leave a Comment

Your email address will not be published.