Forum Discussion

NisHera's avatar
NisHera
Valued Contributor
8 years ago
Solved

python error in datetime

have a function import datetime def myfun(): string_date = '2016-11-03' myTime =datetime.datetime.strptime(string_date, "%Y-%m-%d") in TC 12 (nothing else in the script) This gives...
  • Silmaril's avatar
    8 years ago

    It is known Python problem not related to TestComplete.

    https://bugs.python.org/issue27400

     

    The workaround is to use alternate version of strptime. It is mentionned in documentation :
    Conversely, the datetime.strptime() class method creates a datetime object from a string representing a date and time and a corresponding format string. datetime.strptime(date_string, format) is equivalent to datetime(*(time.strptime(date_string, format)[0:6])).

     

    import datetime
    import time
    
    def myfun():
      string_date = "2016-11-03"
      format = "%Y-%m-%d"
      try:
          res = datetime.datetime.strptime(string_date, format)
      except TypeError:
          res = datetime.datetime(*(time.strptime(string_date, format)[0:6]))
      Log.Message(res)