String to MMM-YY format

时间:2015-09-01 21:15:21

标签: python

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

1 个答案:

答案 0 :(得分:4)

You should take a look at this strftime reference.

The format you are looking for is:

%b-%y