Rounding the duration of two date values

I have two date values in Python which Im trying to get a rounded duration from.

For example: 01-01-2000 to 12-31-2099 is really "100 years", not "99 years".

I have an example, in Java, but Im not sure how to port this to Python speak:

round(endDateEpochInMilliseconds -startDateEpochInMilliseconds /(365.25 * 24 * 3600 * 1000))

Im sure something similar is doable in Python.

-------------Problems Reply------------

import datetime

date1 =,1,1)
date2 =, 12, 31)

delta = date2-date1

print round(delta.days/365.25,0)

You defently must put endDateEpochInMilliseconds -startDateEpochInMilliseconds into brackets!

round( (endDateEpochInMilliseconds -startDateEpochInMilliseconds) /(365.25 * 24 * 3600 * 1000))

Category:python Views:1 Time:2011-04-05

Related post

  • Duration between two dates in Groovy 2010-05-03

    Is there a way in Groovy to get the duration between two Date objects? The duration format I'm looking for would be something like: 2 days, 10 hours, 30 minutes... Thanks --------------Solutions------------- TimeCategory has some methods for getting

  • Add a duration to a date by DateInterval 2012-02-15

    Possible Duplicate: What date/time functions to use for PHP 5.2 I want to add a duration to a date, I set this code : $date = new DateTime(Date('r')); $date = $date->format("d-m-Y H:i:s"); $interval = new DateInterval('PT1H2M3S'); $date = $date-

  • total call duration and total data usage 2015-03-03

    How to track total call duration & total call data in Lumia 720 windows phone. I am from India. If not give me the name of good apps. And please update this in new firmware asap. --------------Solutions------------- Your carrier may provide a win

  • Excel - calculating durations of time data spread across multiple rows 2008-12-01

    I have a spreadsheet with a dataset of a number of transactions, each of which is composed of substeps, each of which has the time that it occurred. There can be a variable number and order of steps. I'd like to find the duration of each transaction.

  • Rounding up a free text date field, for use a 'Date To' criteria field 2010-07-27

    I've found that the Date.TryParse is pretty lenient on input - so skipping out the day or month will still return a value, though always floor rounded. E.g.: DateTime.TryParse("2010", out testDate) -> 01 Jan 2010 or DateTime.TryParse("may 2010", o

  • Time duration between two dates 2011-05-05

    i need to get the time duration in (hh:mm:ss) format between the two dates 2011/05/05 11:45:02 and 2011/05/01 08:09:57 For example if I had these two dates 2011/05/05 01:18:14 and 2011/05/05 11:00:00, the result would be: 02:18:14 --------------Solut

  • weekdays' duration using boost date 2011-09-07

    Is there a way to get only the no. of weekdays between 2 boost dates. In the following, I'm only getting calendar days. date begin_dt(2011,Aug,3); date end_dt(day_clock::local_day()); days duration=end_dt-begin_dt; std::cout<<"calendar days bet

  • How can I compute a duration from two dates? 2011-10-04

    I have this query, that's been giving me some issues, it looks like this: UPDATE servicecontracts SET planned_duration = (to_char(due_date) - to_char(start_date) + 1) ,actual_duration ='' ,progress = NULL WHERE servicecontractsid = '263' After some r

  • How to get duration of steaming data with GStreamer 2011-11-04

    I'm writing a program for converting media file to mp3 file with GStreamer. It works, but I would like to know the duration of audio stream, too. Following is the simplified code. import logging import pygst pygst.require('0.10') import gst # this is

  • Rounding Time (Duration) 2013-08-03

    I have a worksheet that calculates time (duration) in hh:mm:ss. In another workbook I can only use hh:mm. For accuracy is it possible to round the ss in the form of 0-29= 0, 30-59 = 1, so 12:55:57 becomes 12:56 in the hh:mm workshe --------------Solu

  • time duration between start date and time 2013-11-12

    I am having date time in cell (A1) as20/08/2010 08:00 AM and end date time in cell (B1) as21/08/2010 10:00 PM and I want the answer in ----------Hrs as detailed in time line 20/08/2010 0 Hrs ________________08:00_AM_______________________________12:0

  • Rounding milliseconds of POSIXct in data.table v1.9.2 (ok in 1.8.10) 2014-03-12

    I have a weird result for my data.table v1.9.2 : DT timestamp 1: 2013-01-01 17:51:00.707 2: 2013-01-01 17:51:59.996 3: 2013-01-01 17:52:00.059 4: 2013-01-01 17:54:23.901 5: 2013-01-01 17:54:23.914 str(DT) Classes ‘data.table’ and 'data.frame': 5 obs.

  • PHP round & ceiling not correctly parsing data 2012-03-30

    The numbers that are being pulled from an xml file and then assigned to a variable but are outputted incorrectly. I'm not quite sure why or how to get around it. An example is this. $pricing_high = 1.15; echo $pricing_high; This displays 1.15 obvious

  • Working with call duration data 2014-03-27

    I need to do a vertical lookup and pivot table based on call durations expressed as hh:mm:ss. The formatting keeps reverting to a date, so I'm not able to work with the data. My goal is to be able to segregate calls by duration - # of calls less than

  • Create a query that only shows active records based on start date, duration, and true/false 2010-05-13

    I'm trying to piece together a dynamic view that will give a list of all emails that are still being rejected. Table structure: EmailName - varchar(150) - An email address StartRejection - Date - Day to start rejecting email Duration - Small Int - Du

  • How to round date to 00 or 30? 2011-05-25

    I need 0:30 through 0:59 to round down to 0:30. I need 0:00 through 0:29 to round up to 0:30. Example: 08:56 will round down to 08:30 where 09:00 and 09:01 will need to round up to 09:30. Seconds should be omitted or rounded to :00 --------------Solu

  • SQL Get data from time duration 2012-01-03

    I have a SQL database in which I have a column with DataType DateTime. Now I want particular data with particular time duration of all dates. For example, I want data between 7 o'clock and 8 o'clock from all dates, is there any way? --------------Sol

  • MS Project 2010 open MS Project 2007 file and dates and duration change why? 2014-06-20

    I use MS Project 2010. My vendor is using MS Project 2007. She sends me her file and when I open it, MS Project change dates and durations. The change is not indicated in any way. We only discovered this when we would send emails back and forth to di

  • Duration calculated based on Start and End Date has values other than what I expect 2014-06-20

    Hi I am a new user of MS-Project. Thus even for basic functionalities I am discovering things. Here is one of my initial serious challenge (as an amateur) I am creating a task, and I have left duration column empty but I fill in the Start Date and Fi

Copyright (C), All Rights Reserved.

processed in 0.203 (s). 11 q(s)