McIDAS-V Support Forums

Support and discussion of the McIDAS-V software package
Forum HomeMcIDAS-V Home
It is currently 24 Sep 2020, 04:59

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: abs failing for datetime timedelta
PostPosted: 03 Aug 2017, 19:03 
User avatar

Joined: 19 Jan 2009, 19:16
Posts: 1119
Hi,

I would expect that this piece of code would work okay in the jython shell, but it doesn't...

Code:
from datetime import datetime as dt

dateTime1=dt.strptime('2017-Aug-21 18:50', '%Y-%b-%d %H:%M')
dateTime2=dt.strptime('2017-Aug-20 17:20', '%Y-%b-%d %H:%M')

print (abs(dateTime1 - dateTime2))


Thanks,
Joleen


Top
 Profile  
 
 Post subject: Re: abs failing for datetime timedelta
PostPosted: 03 Aug 2017, 19:15 
User avatar

Joined: 19 Jan 2009, 19:16
Posts: 1119
Sorry, it looks like for python 2.7, the code needs to be

from datetime import datetime as dt

dateTime1=dt.strptime('2017-Aug-21 18:50', '%Y-%b-%d %H:%M')
dateTime2=dt.strptime('2017-Aug-20 17:20', '%Y-%b-%d %H:%M')

print (abs((dateTime1 - dateTime2).total_seconds()))

Thanks,
Joleen


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group