0

How to convert (YY,MM,DD,HH,MM,SS) to the Excel "serial" datetime number.

Example: 12/23/2017 10:00:00 PM to 43092.91667

Below converts the date only, but I need to add the timestamp as well:

def convertDateToExcel(day, month, year) :
    offset = 693594
    itime = date(year,month,day)
    n = itime.toordinal()
    return (n - offset)
hlp
  • 11
  • 4
  • 7
    Possible duplicate of [How to convert a python datetime.datetime to excel serial date number](https://stackoverflow.com/questions/9574793/how-to-convert-a-python-datetime-datetime-to-excel-serial-date-number) – Bishakh Ghosh Apr 01 '18 at 19:12

1 Answers1

1

A prime example of me overthinking the problem :-)

The obvious answer:

   def convertDateToExcel(year, month, day, hour, minute, second) :
          offset = 693594
          itime = date(year,month,day)
          n = itime.toordinal()
          return (n - offset + (60*60*hour + 60*minute + second)/(24*60*60))
hlp
  • 11
  • 4