Search code examples
xlrd

How to get week number from excel sheet?


Here its not printing the week number,how to extract week number for each dates from excel sheet,it showing error like

ValueError: invalid literal for int() with base 10: '2015-08-24 00:00:00'

Here this is the line where iam getting error

print datetime.datetime(int(value[:4]),int(value[0:]),int(value[1:])).isocalendar()[1]

Solution

  • value is the complete String '2015-08-24 00:00:00'. using value='2015-08-24 00:00:00' gives for your integers:

    >>> value='2015-08-24 00:00:00'

    value[:4] results in '2015'

    value[0:] results in '2015-08-24 00:00:00'

    value[1:] results in '015-08-24 00:00:00'

    Instead of that you could use value.split(' ').split('-') to get ['2015', '08', '24'].