from datetime import datetime
import time


def getSqlTimeStr(t=None):
    """Returns a sqlite-compatible time string for the given time value
    (in secs since epoch), or :func:`now()` if it's `None` or negative"""
    if not t or t < 0:
        t = time.time()
    d = datetime.fromtimestamp(t).replace(microsecond=0) # since sql cannot handle this
    return d.isoformat(' ')