0

I am trying to change python datetime into matlab datenum by using this and this

 def datetime2matlabdn(dt):
   ord = dt.toordinal()
   mdn = dt + timedelta(days = 366)
   frac = (dt-datetime(dt.year,dt.month,dt.day,0,0,0)).seconds / (24.0 * 60.0 * 60.0)
   return mdn.toordinal() + frac

when I call datetime2matlabdn(2021-08-28 10:30:00) it throws FOLLOWING ERRORS

datetime2matlabdn(2021-08-28 10:30:00)
Syntax Error: invalid token

what is wrong with my syntax? if I try to remove these zeros then it throws invalid syntax error. I figured out I need to strip the zeros I tried some thing like this but it is not working

dt=dt.strptime('2021-06-28 10:30','%Y-%m-%d %H:%M')
    dn=datetime2matlabdn(dt)

how can I strip my zeros in function. any help would be appreciated.

Katja
  • 131
  • 1
  • 6
  • Please see [the help on formatting](https://stackoverflow.com/help/formatting); don't use a Stack Snippet for code that doesn't run in one, such as MATLAB or Python. Simply indent by four spaces or use triple backticks to make the syntax highlighting show up. – Adriaan May 17 '22 at 10:22
  • I don9t know why they close the question when I mentioned that I am getting error in running the code. it throws invalid token error – Katja May 17 '22 at 10:31

0 Answers0