Calculate the time elapsed

Hi,

I have a string with following format: “2012-03-18 06:53:15 UTC”
I need to convert this string to a date and calculate the time that has passed since that date. Also it should be timezone aware.
This elapsed time should have a simple format like: 2 minutes or 10 hours or 3 days or 2 weeks, etc.
Does anyone knows a script I could reuse to accomplish this?

Thank you [import]uid: 189638 topic_id: 33755 reply_id: 333755[/import]

Have you tried Lua’s native os.time function ?
It basically returns the current time, but it can be passed string patterns to format the output. [import]uid: 142361 topic_id: 33755 reply_id: 134189[/import]

Check out this post on Stack Overflow…
http://stackoverflow.com/questions/4105012/changing-string-date-to-a-timestamp-in-lua

The idea, use string patterns to convert the string into each component since you know where they are in the string. Once you have day, month, year, etc. You can use the os.time function to get a Unix timestamp (a number of seconds since Jan 1, 1970, the unix standard 0 date). With the time in seconds now you can easily add or subtract time like

time = time + 60

to add 1 minute or:

time = time + (60 * 60 * 24)

to add a day.
[import]uid: 199310 topic_id: 33755 reply_id: 134230[/import]

Have you tried Lua’s native os.time function ?
It basically returns the current time, but it can be passed string patterns to format the output. [import]uid: 142361 topic_id: 33755 reply_id: 134189[/import]

Check out this post on Stack Overflow…
http://stackoverflow.com/questions/4105012/changing-string-date-to-a-timestamp-in-lua

The idea, use string patterns to convert the string into each component since you know where they are in the string. Once you have day, month, year, etc. You can use the os.time function to get a Unix timestamp (a number of seconds since Jan 1, 1970, the unix standard 0 date). With the time in seconds now you can easily add or subtract time like

time = time + 60

to add 1 minute or:

time = time + (60 * 60 * 24)

to add a day.
[import]uid: 199310 topic_id: 33755 reply_id: 134230[/import]