openpyxl: Why is 3 microseconds added to date/times?

173 views
Skip to first unread message

python...@raf.org

unread,
Aug 22, 2019, 10:09:57 PM8/22/19
to python...@googlegroups.com
Hi,

macosx-10.11.6, python-2.7.16 and python-3.7.4, openpyxl==2.6.3

I'm seeing some strange behaviour reading cells with a
date and time. They come as a datetime.datetime object
with 3 microseconds added to the actual date/time in
the cell.

I have a test spreadsheet where every such cell has the
3 microseconds added to it.

Does anyone know why that is? Or is it just me?

cheers,
raf

Joe Cool

unread,
Sep 13, 2020, 3:27:06 PM9/13/20
to python-excel
Could this be a rounding error?  Excel stores datetime as a floating point number.
--joe

raf

unread,
Sep 13, 2020, 7:53:50 PM9/13/20
to python...@googlegroups.com
On Sun, Sep 13, 2020 at 10:58:28AM -0700, Joe Cool <snoo...@gmail.com> wrote:

> On Thursday, August 22, 2019 at 10:09:57 PM UTC-4 python...@raf.org wrote:
>
> > Hi,
> >
> > macosx-10.11.6, python-2.7.16 and python-3.7.4, openpyxl==2.6.3
> >
> > I'm seeing some strange behaviour reading cells with a
> > date and time. They come as a datetime.datetime object
> > with 3 microseconds added to the actual date/time in
> > the cell.
> >
> > I have a test spreadsheet where every such cell has the
> > 3 microseconds added to it.
> >
> > Does anyone know why that is? Or is it just me?
> >
> > cheers,
> > raf
>
> Could this be a rounding error? Excel stores datetime as a floating point
> number.
> --joe

Perhaps, but I'd wouldn't expect exactly three microseconds
every time. That doesn't feel like a rounding error. I never
got an answer to this question. I just had to discard the
microseconds because I knew none of people creating xlsx
files that I had to import would ever actually include
microseconds in their date/times.

cheers,
raf

Joe Cool

unread,
Sep 14, 2020, 3:05:20 AM9/14/20
to python-excel
Yeah maybe just round the values to the nearest millisecond or second or whatever resolution makes sense for your application.
Reply all
Reply to author
Forward
0 new messages