简体   繁体   中英

String to MMM-YY format

I am using xlrd to read a spreadsheet and write to a database. However, there is a cell value which needs to be written to a date column in the database. The cell is a string and I read it as and trying to convert it to MON-YY as follows.

    sales_month_val = curr_sheet.cell(1,5).value
    print sales_month_val
    current_sales_month = datetime.strptime(sales_month_val,'%MMM%-%YY%')

But I keep getting the conversion failed error message. Is the above conversion to datetime correct to convert to MON-YY format?

Thanks, bee

You should take a look at this strftime reference .

The format you are looking for is:

%b-%y

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