Difference of Two Dates #----------------------------- # Dates produce timedeltas when subtracted. diff = date2 - date1 diff = datetime.date(year1, month1, day1) - datetime.date(year2, month2, day2)#----------------------------- bree = datetime.datetime(1981, 6, 16, 4, 35, 25) nat = datetime.datetime(1973, 1, 18, 3, 45, 50)
difference = bree - natprint "There were", difference, "minutes between Nat and Bree"#=> There were 3071 days, 0:49:35 between Nat and Bree weeks, days = divmod(difference.days, 7) minutes, seconds = divmod(difference.seconds, 60) hours, minutes = divmod(minutes, 60) print "%d weeks, %d days, %d:%d:%d" % (weeks, days, hours, minutes, seconds)#=> 438 weeks, 5 days, 0:49:35#----------------------------- print "There were", difference.days, "days between Bree and Nat." #=> There were 3071 days between bree and nat Origin: http://pleac.sourceforge.net/pleac_python/datesandtimes.html Ovidio Marinho Falcao Neto Web Developer ovidio...@gmail.com ovidiomari...@itjp.net.br ITJP - itjp.net.br 83 8826 9088 - Oi 83 9334 0266 - Claro Brasil 2012/7/20 Jonathan Lundell <jlund...@pobox.com> > On 20 Jul 2012, at 6:19 AM, Andrew wrote: > > I'm not sure if web2py has something built-in to do this calculation but > for other similar issues in the past I've just converted my dates to epoch > and done the necessary math to see the difference between the two > date-times. > > > web2py ordinarily deals with datetime fields as Python datetime objects, > which can just be compared (with due allowance for timezones). request.now > has the current local time as a datetime; request.utcnow has UTC. > > I use epoch dates myself in some cases, in particular to communicate with > iOS clients through JSON, passing them as integers. The Python docs have > quite a bit of material on manipulating dates, though it's a bit confusing > in places. The modules of most interest are datetime, time and calendar. > > > On Thursday, July 19, 2012 4:05:41 AM UTC-5, Amit wrote: >> >> Hi, >> I have some records in a table and each record is having one field of >> type datetime [fromat : 2012-07-19 23:12:0 (YYYY-MM-DD HH:MM:SS)], table >> structure is: >> >> Emp_ID >> Emp_Name >> Emp_Address >> Emp_Salary >> updated_on(Type: datetime) >> >> periodically getting data against each Emp_ID and updating to the >> particular record, every 20 mins data has to be updated for each Emp_ID, >> for e.g : suppose for one Emp_ID data has updated on 2012-07-19 10:10:00 >> then again it has to update on 2012-07-19 10:30:00 etc... >> >> and if data is not updated in 20 mins then one scheduler will verify >> against the updated_on column value and inform user that data has not >> updated for particular employee. >> >> Problem facing: >> How to compare current datetime with updated_on coulmn value in web2py? >> can anybody please share me the code to achieve the same? >> > > > > > -- > > > > --