code: def toDatetime(value, format=None):
      
      if value and value is not None:
          if format:
              value = datetime.strptime(value, format)
          else:
              # https://bugs.python.org/issue30684
              # And platform support for before epoch seems to be flaky.
              # TODO check for others errors too.
              if int(value) == 0:
                  value = 86400
              value = datetime.fromtimestamp(int(value))
      return value
docs: Returns a datetime object from the specified value.
  
          Parameters:
              value (str): value to return as a datetime
              format (str): Format to pass strftime (optional; if value is a str).