如何从string
邮票格式的DateTime
中提取月份和年份?
sales_close_7 = 2018-12-07
答案 0 :(得分:1)
import datetime
sales_close_7 = '2018-12-07'
date_object = datetime.datetime.strptime(sales_close_7, '%Y-%m-%d').date()
print(date_object.year)
Output: 2018
print(date_object.month)
Output: 12