MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / convert_date

Function convert_date

pymysql/converters.py:289–307  ·  view source on GitHub ↗

Returns a DATE column as a date object: >>> convert_date('2007-02-26') datetime.date(2007, 2, 26) Illegal values are returned as str: >>> convert_date('2007-02-31') '2007-02-31' >>> convert_date('0000-00-00') '0000-00-00'

(obj)

Source from the content-addressed store, hash-verified

287
288
289def convert_date(obj):
290 """Returns a DATE column as a date object:
291
292 >>> convert_date('2007-02-26')
293 datetime.date(2007, 2, 26)
294
295 Illegal values are returned as str:
296
297 >>> convert_date('2007-02-31')
298 '2007-02-31'
299 >>> convert_date('0000-00-00')
300 '0000-00-00'
301 """
302 if isinstance(obj, (bytes, bytearray)):
303 obj = obj.decode("ascii")
304 try:
305 return datetime.date(*[int(x) for x in obj.split("-", 2)])
306 except ValueError:
307 return obj
308
309
310def through(x):

Callers 1

convert_datetimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected