473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calculating timespan

I've been looking at the date/time classes and I'm at a loss as to how
to do this (probably too used to other platforms).

I have two date/time values. One represents 'now' and the other the last
modified time of a file on disk (from stat). I need to calculate the
difference in time (i.e., a 'timespan') between the two so I can tell if
the file has been modified in the past X minutes and do something to it.

Thanks =)
Sep 28 '08 #1
2 7351
Erhard napisał(a):
I've been looking at the date/time classes and I'm at a loss as to how
to do this (probably too used to other platforms).

I have two date/time values. One represents 'now' and the other the last
modified time of a file on disk (from stat). I need to calculate the
difference in time (i.e., a 'timespan') between the two so I can tell if
the file has been modified in the past X minutes and do something to it.

Thanks =)
You can subtract one datetime object from another:

from datetime import datetime, timedelta
span = datetime.now() -
datetime(year=2008,month=8,day=27,hour=12,minute=3 4,second=56)
if span < timedelta(minutes=37):
# do something
Sep 28 '08 #2
ma*********@wp.pl wrote:
from datetime import datetime, timedelta
span = datetime.now() -
datetime(year=2008,month=8,day=27,hour=12,minute=3 4,second=56)
if span < timedelta(minutes=37):
# do something
timedelta! Yes, it's obvious that's what I was looking for. I was stuck
with 'timespan' in my head and couldn't find anything like it in the docs.

Thank you very much!
Sep 28 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ron Vecchi | last post by:
I need to calculate the age of a person based on a DateTime BirthDate I was thinking TimeSpan ts = DateTime.Now - BirthDate; //I can get the days but not years. // I could check each...
2
by: Philip Townsend | last post by:
I need to add together some times that are stored in a database as seperate int values. Here is a code segment that is flawed (ts is declared as: TimeSpan ts=new TimeSpan(0,0,0). As is, the value...
2
by: Jeff Shantz | last post by:
Hello, I'm developing a large statistics application for a call center. It often needs to calculate time spanning over months. For example, an agent's total talk time within 30 days. Since an...
2
by: Paul Aspinall | last post by:
Hi I want to calculate the difference between 2 dates in C#. I know there is a function in VB, called DateDiff, but I don't want to ref the VB library, and want to try to do it natively in C#. ...
3
by: DBLWizard | last post by:
Howdy, I have looked and don't see a straight forward way to calculate time differences in milliseconds. What I am wanting to do is benchmark or time how long things take. So I want to...
5
by: Carlos | last post by:
Hi all, I have used the datetime class, but I just came up with a situation that need to have some advise. If I now how much time have passed, can I know the original date?. Lets say that I know...
4
by: Peter Proost | last post by:
Hi group, it's been a long time since the last time I've been here but I have a question. I'm working with timespan.parse for calculating a duration, I have to add strings which are in the...
5
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: ...
0
by: tnynyn | last post by:
I have created a form with two datetimepicker showing only hours (start and end times). I have timespan calculating the total hours, but when it goes to the next day, it adds 24 hours. For example,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.