I had encountered a similar problem. I converted both the dates to time since epoch and then computed their difference and then made the new time...
On Thu, Feb 19, 2009 at 4:51 PM, <bangpypers-requ...@python.org> wrote: > Send BangPypers mailing list submissions to > bangpypers@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/bangpypers > or, via email, send a message with subject or body 'help' to > bangpypers-requ...@python.org > > You can reach the person managing the list at > bangpypers-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of BangPypers digest..." > > > Today's Topics: > > 1. Re: date/time difference between two dates (Parthan SR) > 2. Re: date/time difference between two dates (Saju Pillai) > 3. Re: date/time difference between two dates (Ruchir Shukla) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 19 Feb 2009 16:37:29 +0530 > From: Parthan SR <parth.technofr...@gmail.com> > Subject: Re: [BangPypers] date/time difference between two dates > To: Bangalore Python Users Group - India <bangpypers@python.org> > Message-ID: <499d3d71.4080...@gmail.com> > Content-Type: text/plain; charset=UTF-8; format=flowed > > LOhit wrote: > > My question is, the date is in "Month day-of-the-month time" format in > > the log file (ex. "Nov 22 15:15:42") and the current date I get from > > "datetime" module is in ISO format. How do I convert the date in log > > file to ISO format(or any other format) and then compare with the > > current date/time. > > >>> import datetime # or try `from datetime import datetime` and use > `datetime.today()` > > >>> datetime.datetime.today() > datetime.datetime(2009, 2, 19, 16, 34, 40, 358989) > > >>> datetime.datetime.today().strftime("%d-%m-%Y") > '19-02-2009' > > >>> today=datetime.datetime.today().strftime("%d-%m-%Y") > >>> today > '19-02-2009' > > >>> today_dtobj=datetime.datetime.strptime(today, "%d-%m-%Y") > >>> today_dtobj > datetime.datetime(2009, 2, 19, 0, 0) > > >>> type(today_dtobj) > <type 'datetime.datetime'> > > -- > With Regards, > > Parthan "technofreak" (2FF01026) > http://technofreak.in > > > > ------------------------------ > > Message: 2 > Date: Thu, 19 Feb 2009 16:39:26 +0530 > From: Saju Pillai <saju.pil...@gmail.com> > Subject: Re: [BangPypers] date/time difference between two dates > To: Bangalore Python Users Group - India <bangpypers@python.org> > Message-ID: <499d3de6.1020...@gmail.com> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > LOhit wrote: > > Hello All, > > > > I am parsing a log file to extract data for the last one week from the > > current date. The log file does not record the year, only month, day of > > the month and time. > > > > My question is, the date is in "Month day-of-the-month time" format in > > the log file (ex. "Nov 22 15:15:42") and the current date I get from > > "datetime" module is in ISO format. How do I convert the date in log > > file to ISO format(or any other format) and then compare with the > > current date/time. > > Look at time.strptime() or datetime.strptime(). > > This method takes the string to be parsed and the format of the string. > > For eg: > > time_object = time.strptime("Nov 22 15:15:42", "%b %d %H:%M:%S") > > This will give you a time object on which you can call strftime(format, > time_object) where format is any format you want. > > In your particular case, the year will default to 1900, you may want to > explicitly supply the year like strptime("2008 Nov 22 15:15:42", "%Y %b > %d %H:%M:%S"). > > > srp > -- > http://saju.net.in > > > ------------------------------ > > Message: 3 > Date: Thu, 19 Feb 2009 16:49:02 +0530 > From: Ruchir Shukla <ruchiryshu...@gmail.com> > Subject: Re: [BangPypers] date/time difference between two dates > To: bangpypers@python.org > Message-ID: <1235042342.15032.2.ca...@ping> > Content-Type: text/plain; charset="us-ascii" > > import datetime > curr_date = datetime.datetime.now() > final_date = curr_date.strftime('%h %d %H:%M:%S') > print "::::FINAL DATE:::::",final_date > > here is the demo to convert the current date into yr needed format > > > > > Message: 4 > > Date: Thu, 19 Feb 2009 16:29:01 +0530 > > From: LOhit <lohi...@gmail.com> > > Subject: [BangPypers] date/time difference between two dates > > To: bangpypers@python.org > > Message-ID: > > <29117e150902190259j700bc28bp3975fe8c0e7b3...@mail.gmail.com> > > Content-Type: text/plain; charset="iso-8859-1" > > > > Hello All, > > > > I am parsing a log file to extract data for the last one week from the > > current date. The log file does not record the year, only month, day of > the > > month and time. > > > > My question is, the date is in "Month day-of-the-month time" format in > the > > log file (ex. "Nov 22 15:15:42") and the current date I get from > "datetime" > > module is in ISO format. How do I convert the date in log file to ISO > > format(or any other format) and then compare with the current date/time. > > > > I am sure this will sound like a simple problem to you experts, but, I am > > not a programmer. I am a python enthusiast trying to automate few of my > > jobs. > > > > Thanks, > > > > > > ________________________________________________________________________ > > Thanks & Regards, > Ruchir Shukla > Application Engineer > > > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/bangpypers/attachments/20090219/4c93207b/attachment.htm > > > -------------- next part -------------- > A non-text attachment was scrubbed... > Name: openerp_big.png > Type: image/png > Size: 8725 bytes > Desc: not available > URL: < > http://mail.python.org/pipermail/bangpypers/attachments/20090219/4c93207b/attachment.png > > > > ------------------------------ > > _______________________________________________ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > > > End of BangPypers Digest, Vol 18, Issue 26 > ****************************************** >
_______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers