473,385 Members | 1,753 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.

Comparing the date in a file to present date

i have a file with lines like

akdvalues[0]["day"]="16.10.11";

akdvalues[1]["day"]="17.10.11";

.....

so i need to pick these date and compare with present day and do for all the dates in the file
Dec 1 '11 #1
1 1716
bvdet
2,851 Expert Mod 2GB
Assuming you can parse the date, you can create a struct_time object and compare to the current time to determine the difference in seconds. Example
Expand|Select|Wrap|Line Numbers
  1. >>> s = "16.10.11"
  2. >>> import time
  3. >>> timeObj = time.strptime(s, "%d.%m.%y")
  4. >>> diff = time.time() - time.mktime(timeObj)
  5. >>> diff
  6. 4013380.8589999676
  7. >>> diff/86400.0
  8. 46.462851018519316
  9. >>> 
You can also do something similar used in combination with a datetime.datetime() object.
Expand|Select|Wrap|Line Numbers
  1. >>> import datetime
  2. >>> present = datetime.datetime.now()
  3. >>> present
  4. datetime.datetime(2011, 12, 1, 10, 1, 20, 593000)
  5. >>> then = datetime.datetime(*timeObj[:6])
  6. >>> diff = present-then
  7. >>> diff.days
  8. 46
  9. >>> diff.seconds
  10. 36080
  11. >>> 
Dec 1 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: AA Arens | last post by:
I have a field "Notes" and I would like to have a button in the vicinity doing the following: It goes to the end of the present text, already filled in the Note-field, performs a and put in the...
4
by: wil | last post by:
Dear All, In the linux platform, is there anyway I can in a C program change the file create date? Thanks, wil.
1
by: .Net Sports | last post by:
I need to parse the date I'm getting from this sqlstring to compare it with today's date. If it's before today's date, i need to show the viewers one page. If it is after today's date, then I need...
3
by: prakashsurya | last post by:
Hi experts gud evenin i am having a small doubt that is i have to display the present date in a text box by using scripting and that should be refreshed day after day i mean today is 28 th so...
9
shrek123
by: shrek123 | last post by:
How to write to a ".txt" file present on remote machine. I dont want to use two way socket connection. Is there any other way to write to a file on remote machine? Best Regards, Shrek.
4
by: anagai | last post by:
I just want to check if a date entered in a textbox is equal to the current system date. I set the date object from the input field like this: dt1=new Date('10/01/2007'); the current system...
1
by: abdutasleem357 | last post by:
i want to know the query in oracle for, whether the given date is present or available in between two dates(startdate, enddate)
0
by: Syed Khaleel Ahamed | last post by:
Dear Sir, I want to get the difference of date/time captured in mysql and present date/time in jsp. I am using the following code to get, but its getting difference only in hrs, i used...
2
Soniad
by: Soniad | last post by:
Hi, In my website, I show commodity details on daily basis.These details are stored in one table for each day. I select record by matching current date and current date records are...
1
by: vasavivenu | last post by:
Hi, I need to calculate the Expire Date by adding of days/months in c#. For Example: I give present date as 08-03-2011, and i gave period of time as 3 months then i need the 09-06-2011. ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.