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
#4
In [1]: matlab_datenum =  63650171169.50261

In [2]: matlab_datenum/1000/86400  # days
Out[2]: 736.6917959433172
If its really miliseconds, then its counting them from date in October 2008, seems quite odd. As i said, you would need to use some "offset".

In [3]: import datetime

In [4]: some_matlab_date = matlab_datenum - 1000000000 # million seconds earlier?

In [5]: some_python_date = ( datetime.datetime(2010, 11, 4, 0, 3, 50)   # your base date
                             + datetime.timedelta(seconds = (some_matlab_date - matlab_datenum)/1000) )

In [6]: some_python_date
Out[6]: datetime.datetime(2010, 10, 23, 10, 17, 10)
You just take your 2010/11/4 as a base date and add difference between matlab representation of that date and another one.

EDIT: You can use that formula to compute "start of matlab calender" by setting some_matlab_date = 0 and after that you could use
 some_python_date = python_datetime_of_start_of_matlab_calendar + datetime.timedelta(seconds = some_matlab_date/1000)
Reply


Messages In This Thread
RE: Error when converting MATLAB's datenum to Python's datetime - by zivoni - Mar-31-2017, 11:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Value error when converting hex value to bytearray shubhamjainj 7 10,660 Mar-20-2023, 05:30 PM
Last Post: Skaperen
  Converting python to FileMaker DWolf 6 1,779 Sep-22-2022, 03:40 AM
Last Post: DWolf
  Error when Excelwriter saving a dataframe with datetime datatype with timezone klllmmm 3 13,617 Dec-08-2020, 11:37 AM
Last Post: Larz60+
Photo Matlab to Python Sateesh 0 1,709 Nov-04-2020, 09:11 AM
Last Post: Sateesh
  From Matlab to Python erbab 1 2,050 Oct-27-2020, 02:16 PM
Last Post: jefsummers
  Arrays in MATLAB and PYTHON cokhuatlanyeuthuongconhetmuc 2 2,225 Jul-24-2020, 10:47 AM
Last Post: cokhuatlanyeuthuongconhetmuc
  Matlab to Python -- Parallel Computing zistambo 1 2,001 Jun-10-2020, 04:59 PM
Last Post: pyzyx3qwerty
  Python v MatLab for graphs and plots CynthiaMoore 4 3,103 Apr-22-2020, 02:13 PM
Last Post: CynthiaMoore
  python equivalent to MATLAB xcov chai0404 2 3,921 Apr-02-2020, 10:29 PM
Last Post: chai0404
  Python equivalent of Matlab code kwokmaster 1 3,503 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