easymacro/docs/en/docs/tools/datetime.md

2.1 KiB

!!! tip "Attention"

Start date in Calc and Python are different.

today

Get current date.

    d = app.dates
    app.msgbox(d.today)

now

Get current date and time.

    d = app.dates
    app.msgbox(d.now)

time

Get current time.

    d = app.dates
    app.msgbox(d.now.time())

epoch

Get Unix time

    d = app.dates
    app.msgbox(d.epoch)

date

Get a date.

    d = app.dates

    date = d.date(1974, 1, 15)
    app.msgbox(date)

time

Get a time.

    d = app.dates

    time = d.time(10, 20, 15)
    app.msgbox(time)

datetime

Get date and time.

    d = app.dates

    dt = d.datetime(1974, 1, 15, 10, 11, 12)
    app.msgbox(dt)

str_to_date

String to date. Look this excellent info

    d = app.dates

    str_date = '1974-01-15'
    template = '%Y-%m-%d'
    obj_date = d.str_to_date(str_date, template)
    app.msgbox(obj_date)
    app.msgbox(type(obj_date))

Get a valid date for insert in a Calc cell.

    d = app.dates

    str_date = '1974-01-15'
    template = '%Y-%m-%d'
    obj_date = d.str_to_date(str_date, template, True)
    app.msgbox(obj_date)
    app.msgbox(type(obj_date))

calc_to_date

Converts a value to Python date, for example, the initial date set in Calc.

    d = app.dates

    value = 0
    obj_date = d.calc_to_date(value)
    app.msgbox(obj_date)
    app.msgbox(type(obj_date))

sleep

Pause execution for X seconds.

!!! tip inline end "Attention"

The pause is blocking.
    d = app.dates

    app.sleep(3)
    app.msgbox('End')

start and end

Measure time in seconds.

    d = app.dates

    d.start()
    app.sleep(5)
    seconds = d.end()
    app.msgbox(seconds)

Get timedelta instead of seconds

    d = app.dates

    d.start()
    app.sleep(5)
    td = d.end(False)
    app.msgbox(td)