Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date after number of days in lua scripting

I am new to lua scripting. I have a startDate ("03-05-2014" as "dd-mm-yyyy") and a span in days (2) Can anyone help me how to get the endDate based on the startDate and span?.

Example startDate     span            endDate 
        ---------     ----            -------
        03-05-2014     2             05-05-2014
       (dd-mm-yyyy)                 (dd-mm-2014)
like image 990
Vijay Avatar asked May 06 '14 05:05

Vijay


1 Answers

You don't need to do any math here. os.time and os.date will do it for you.

local day, month, year = ("03-05-2014"):match("(%d%d)-(%d%d)-(%d%d%d%d)")
local span = 64
local endtime = os.time({day = day + span, month = month, year = year})
print(os.date("%c", endtime))
like image 136
Etan Reisner Avatar answered Sep 24 '22 04:09

Etan Reisner