[CODE] cool elapsed function

Peter Haworth pete at lcsql.com
Tue Dec 18 12:31:17 EST 2012


Hi Jacque,
I realize not all applications us an sqlite database but for those that do,
sqlite has extremely powerful date calculation features.  Space prohibits
going into all the details but here's a few examples.

To get the number of days between two dates:
SELECT julianday('now') - julianday('1776-07-04')

To get the number of seconds between two dates:
SELECT strftime('%s','now') - strftime('%s','2004-01-01 02:34:56')

To get the number of minutes, divide the result of the above by 60;hours
divide by 3600.

Lots of other things you can do, for example  to compute the date of the
first Tuesday in October for the current year:
SELECT date('now','start of year','+9 months','weekday 2')

All that's needed is one call to revdb_querylist.

Date/time manipulation is so easy with sqlite that even if my application
doesn't need an sqlite database, I open an in-memory, empty database anyway
if I need to do date calculations:

put revOpenDatabase("sqlite",":memory::,,,) into tdbid

Pete
lcSQL Software <http://www.lcsql.com>



On Mon, Dec 17, 2012 at 6:55 PM, J. Landman Gay <jacque at hyperactivesw.com>wrote:

> On 12/17/12 10:46 AM, Andre Garzia wrote:
>
>  the function is called elapsed and you can use it to figure out if a
>> certain amount of time passed between two timestamps.
>>
>
> I'd like a function that returns years, months, and days elapsed. I wrote
> a quick one that gets the number of days and divides by 30 to get months
> and days but it isn't very accurate. Since it's just for me I haven't gone
> back to fix it. Anyone have one already written?
>
> --
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
>
> ______________________________**_________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/**mailman/listinfo/use-livecode<http://lists.runrev.com/mailman/listinfo/use-livecode>
>



More information about the use-livecode mailing list