I have a date with some string in excel cell like, 'As of 09-Jan-2019' I need to parse this date and convert it into yyyy/mm/day format
'to_search = "%d-%b-%y"'
'for i in range(sheet.ncols):'
'for j in range(sheet.nrows):'
'if sheet.cell_value(i,j) == re.search(to_search, txt)'
'print sheet.cell_value(i,j)'
Thanks in advance
Using python you can do it with dateutil lib ( pip install python-dateutil
) and some initial string slicing:
import dateutil.parser
s = 'As of 09-Jan-2019'
t = dateutil.parser.parse(s[5:])
t.strftime('%Y/%m/%d')
returns 2019/01/09
from datetime import datetime
date = "09-Jan-2019"
new_date_format=datetime.strptime(date, "%d-%b-%Y").date()
print(new_date_format)
import xlrd
loc = ("path of file")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)
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.