This topic contains 2 replies, has 2 voices, and was last updated by  Sandeep 1 month, 3 weeks ago.

Get previous day's date in LUA

  • What is the best way to get the previous day’s date in Lua? I tried subtracting 1 from*t) table, but it doesn’t work if the current date is 01/xx/2019.

    I also tried:“%Y-%m-%d”,os.time()-24*60*60)

    but getting this error

    attempt to perform arithmetic on a userdata value

    Thank you.

    There’s an example of date math near the end of this thread. Should be easy to adapt to your needs.

    Jeff Drumm ◊ VP and COO ◊ HICG, LLC. ◊

    Hi Jeff, It worked. Thank you. You are awesome

    pastOrFuture = string.lower(pastOrFuture)
    local currrentDate =‘*t’)
    local atime = os.ts.time({year=currrentDate.year,month=currrentDate.month,,hour=0,min=0,sec=0}) — create epoch time
    local adayInSeconds = (60 * 60 * 24*NumberOfDays )
    local btime
    if(pastOrFuture ==’past’) then
    btime = atime – adayInSeconds
    btime = atime + adayInSeconds
    local adate =‘%d%m%Y’,btime)

    Thank you

You must be logged in to reply to this topic.