Python Forum
Error when converting MATLAB's datenum to Python's datetime
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error when converting MATLAB's datenum to Python's datetime
#1
Hello,

I have to convert a MATLAB's datenum to Python's datetime. The following code is as below:

import datetime
matlab_datenum = 63650571169.50261
python_datetime = datetime.date.fromordinal(int(matlab_datenum)) + datetime.timedelta(days=matlab_datenum%1) -  datetime.timedelta(days = 366)
print (matlab_datenum)
63650571169.50261 is a datenum that represents a date plus a time for example 2010-11-04 00:03:50.209589

The above code generates this error:

OverflowError: Python int too large to convert to C long
 
The above code, is it correct ? how can i obtain a date plus a time ?

Thank you for your help,
Reply


Messages In This Thread
Error when converting MATLAB's datenum to Python's datetime - by zoya2385 - Mar-31-2017, 10:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Value error when converting hex value to bytearray shubhamjainj 7 10,575 Mar-20-2023, 05:30 PM
Last Post: Skaperen
  Converting python to FileMaker DWolf 6 1,710 Sep-22-2022, 03:40 AM
Last Post: DWolf
  Error when Excelwriter saving a dataframe with datetime datatype with timezone klllmmm 3 13,454 Dec-08-2020, 11:37 AM
Last Post: Larz60+
Photo Matlab to Python Sateesh 0 1,690 Nov-04-2020, 09:11 AM
Last Post: Sateesh
  From Matlab to Python erbab 1 2,031 Oct-27-2020, 02:16 PM
Last Post: jefsummers
  Arrays in MATLAB and PYTHON cokhuatlanyeuthuongconhetmuc 2 2,211 Jul-24-2020, 10:47 AM
Last Post: cokhuatlanyeuthuongconhetmuc
  Matlab to Python -- Parallel Computing zistambo 1 1,981 Jun-10-2020, 04:59 PM
Last Post: pyzyx3qwerty
  Python v MatLab for graphs and plots CynthiaMoore 4 3,075 Apr-22-2020, 02:13 PM
Last Post: CynthiaMoore
  python equivalent to MATLAB xcov chai0404 2 3,894 Apr-02-2020, 10:29 PM
Last Post: chai0404
  Python equivalent of Matlab code kwokmaster 1 3,468 Mar-25-2020, 10:14 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020