def get_datetime(index_timestamp, timestring):
 if ('%W' in timestring):
  timestring += '%w'
  index_timestamp += '1'
 elif ('%U' in timestring):
  timestring += '%w'
  index_timestamp += '1'
 elif ('%m' in timestring):
  if (not ('%d' in timestring)):
   timestring += '%d'
   index_timestamp += '1'
 return datetime.strptime(index_timestamp, timestring)

def get_datetime ( index_timestamp , timestring ) : if ( '%W' in timestring ) : timestring += '%w' index_timestamp += '1' elif ( '%U' in timestring ) : timestring += '%w' index_timestamp += '1' elif ( '%m' in timestring ) : if ( not ( '%d' in timestring ) ) : timestring += '%d' index_timestamp += '1' return datetime . strptime ( index_timestamp , timestring )
return a datetime object .