[web2py] Re: how to compare date time in web2py?

2017-05-28 Thread Peter
I had some fun with this

max_age_allowed = 20 * 60  # total seconds in 20 minutes
update_age = request.now - person.created_on  # Duration in datetime format 
since record created
update_age = update_age.total_seconds()   # Duration converted to seconds
print "It is %s seconds since record created (threshold is %s seconds)" % 
(update_age,max_age_allowed )
if update_age > max_age_allowed:
print 'Do something'
else:
print 'Nothing to do here'



output

It is 2102030.41814 seconds since record created (threshold is 1200 seconds)
Do something

Hope this helps.





On Thursday, 19 July 2012 10:05:41 UTC+1, 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 (-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?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: how to compare date time in web2py?

2017-05-26 Thread akshay05kumar
You can compare time here by using the relational operators. Access the 
current time by using 'request.now' (its value will be in same format as 
'update_on' field of your table) then you can just compare it as :

if (dbquery).updated_time > request.now:
//do something






On Thursday, July 19, 2012 at 2:35:41 PM UTC+5:30, 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 (-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?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: how to compare date time in web2py?

2012-07-20 Thread Ovidio Marinho
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 

> 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 (-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?
>>
>
>
>
>
>  --
>
>
>
>

-- 





Re: [web2py] Re: how to compare date time in web2py?

2012-07-20 Thread Jonathan Lundell
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 (-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?
> 
> 


-- 





[web2py] Re: how to compare date time in web2py?

2012-07-20 Thread Andrew
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. 

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 (-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?
>

-- 





[web2py] Re: how to compare date time in web2py?

2012-07-19 Thread Niphlod
current datetime is:
request.now

or 
import datetime
datetime.datetime.now()

Il giorno giovedì 19 luglio 2012 11:05:41 UTC+2, Amit ha scritto:
>
> 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 (-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?
>

--