[quote=“rob,post:2,topic:309743”]
basically you have to parse the string into its component numbers, but its really not that hard. Here is a function I use for it:
function M.makeTimeStamp(dateString) local pattern = "(%d+)%-(%d+)%-(%d+)T(%d+):(%d+):(%d+)([%+%-])(%d+)%:(%d+)" local xyear, xmonth, xday, xhour, xminute, xseconds, xoffset, xoffsethour, xoffsetmin = dateString:match(pattern) local convertedTimestamp = os.time({year = xyear, month = xmonth, day = xday, hour = xhour, min = xminute, sec = xseconds}) local offset = xoffsethour \* 60 + xoffsetmin if xoffset == "-" then offset = offset \* -1 end return convertedTimestamp + offsetend
This looks much scarier than it really is. The goal is to turn that string into a Unix timestamp (number of seconds since Jan 1, 1970, the standard used by most systems). So we use the string.match() method to fetch the various date and time parts into their own variables: xyear, xmonth,etc.
Next we use the API call os.time() to convert all those individual parts into the timestamp. My code tries to adjust for time zones…
Now you have the time in a nice integer that you can easily manipulate and do date math. Now to determine how many days have passed since that date:
then = makeTimeStamp("2013-01-01T00:00:00Z")now = os.time()timeDifference = now - thendaysDifference = math.floor(timeDifference / (24 \* 60 \* 60)) -- 24 hours, 60 min, 60 seconds. I think it works out to 86400 seconds in a day or something like that...
[import]uid: 199310 topic_id: 34760 reply_id: 138198[/import] [/quote]
I get an error using this, it says “Field ‘day’ missing in date table”.
xday is indeed nil (in fact, all the other values too, it seems) from the match on this string: 2013-09-09T00:00:00Z, but… no, I don’t see where the fault lies either.
Any ideas?