Date formatting in Python – use strftime, like Oracle's to_char

time — Time access and conversions — Python v2.6.1 documentation

time.strftime(format[, t])¶

Convert a tuple or struct_time representing a time as returned by gmtime() or localtime() to a string as specified by the format argument. If t is not provided, the current time as returned by localtime() is used. format must be a string. ValueError is raised if any field in t is outside of the allowed range.

The strftime function is similar to Oracle SQL’s to_char function to display a date in various formats.
You will however need to be familiar with directives.

For example, to display a date in Oracle’s format (‘dd-MON-yy’), the function is

assuming d is a datetime,
d.strftime(‘%d-%b-%y’).upper()

Cookie