简体   繁体   中英

Not able to change output timestamp variable in proper oracle standard format

cur.execute("select max(insertdate) from iipmdbse.I_SalesOrder")
data = cur.fetchone()
print(data)

Output :

(datetime.datetime(2019, 12, 17, 10, 1, 22, 634000),)

But I want output in this format 17-DEC-19 10.01.22.634000000 AM .

First, fetchone() returns a tuple of column values so we'll need to unpack that tuple to get the insertdate. Next, we use datetime.strftime to format the date to your liking.

cur.execute("select max(insertdate) from iipmdbse.I_SalesOrder")
data = cur.fetchone()
insertdate, = data
print(insertdate.strftime('%d-%b-%y %I:%M:%S.%f %p').upper())

You need to use to_char function to format the datetime into a character string. Check the Oracle Document for to_char

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM