lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Luiz Henrique de Figueiredo schrieb:
d1.day, d1.month, d1.year = string.gfind( date1, "(%d+).(%d+).(%d+)");
...but gfind do not work for me:-(


You need to ignore the first 2 return values.

... and use string.find instead of string.gfind! string.gfind is meant to be used in for-loops. Btw., I have written some date calculation functions myself. They are not perfect (and not well-tested either), but you could have a look (or use them if you like):

http://www.ratnet.stw.uni-erlangen.de/~siphjand/lua50/date.lua


Try the code below.
--lhf

function str2time(s)
 local d={}
 local a,b
 a, b, d.day, d.month, d.year = string.find(s, "(%d+).(%d+).(%d+)");
 return os.time(d)
end

function diff(a,b)
 return os.difftime(str2time(b),str2time(a))/(60*60*24)
end