473,770 Members | 4,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with time

ian
Hi,

i have a problem with time in python.

1) i got 2 values from mysql db (fields are "time" type)
2) python get it as "<type 'datetime.timed elta'>" (why timedelta???)
3) i need to compare 2 fields with actual time ... EG:
if ArrOutputsAuto[i].TimeFrom >= GNow and ArrOutputsAuto[i].TimeTo <= GNow:

i need actual time, and 2 fields from DB in datetime.time type (correct me
if i'm wrong) so i can do my test "if time>= ..."

I think i can grab time from DB in string and parse it in
datetime.time(x ,x,x) but its not very optimized

Any idea ?

Thanks
Mar 22 '07 #1
3 1551
>
1) i got 2 values from mysql db (fields are "time" type)
2) python get it as "<type 'datetime.timed elta'>" (why timedelta???)
3) i need to compare 2 fields with actual time ... EG:
if ArrOutputsAuto[i].TimeFrom >= GNow and ArrOutputsAuto[i].TimeTo
<= GNow:

i need actual time, and 2 fields from DB in datetime.time type
(correct me
if i'm wrong) so i can do my test "if time>= ..."

I think i can grab time from DB in string and parse it in
datetime.time(x ,x,x) but its not very optimized

Any idea ?
Just a guess, really. Is it perchance a timedelta from the epoch?
If so, comparison should be easy.
Mar 22 '07 #2
ian wrote:
Hi,

i have a problem with time in python.

1) i got 2 values from mysql db (fields are "time" type)
2) python get it as "<type 'datetime.timed elta'>" (why timedelta???)
timedelta because a time doesn't represent a fixed point until it's
associated with a date, I presume.
3) i need to compare 2 fields with actual time ... EG:
if ArrOutputsAuto[i].TimeFrom >= GNow and ArrOutputsAuto[i].TimeTo <= GNow:

i need actual time, and 2 fields from DB in datetime.time type (correct me
if i'm wrong) so i can do my test "if time>= ..."

I think i can grab time from DB in string and parse it in
datetime.time(x ,x,x) but its not very optimized

Any idea ?
Presumably the datetime.timede lta object comes back from the database
with days=0? In which case try something like

import time
import datetime

dbtd = <timedelta from database>
h, m, s = time.localtime( )[3:6]
timenow = s + (60 * (m + 60 * h))

Then compare timenow with dbtd.seconds.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Mar 22 '07 #3
ian

"Steve Holden" <st***@holdenwe b.coma écrit dans le message de news:
ma************* *************** **...*@pyt hon.org...
import time
import datetime

dbtd = <timedelta from database>
h, m, s = time.localtime( )[3:6]
timenow = s + (60 * (m + 60 * h))
Look like ok, thanks all :)
Mar 23 '07 #4

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

Similar topics

9
2646
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php'; global $LOGINDIR;
11
3760
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class (ClassB* b; b->func(); ) the base-class function is called instead of the new function in the derived class. All other similar functions (virtual in the base class and overwritten in the the derived class) work fine, it's just this one function. ...
4
2417
by: Gactimus | last post by:
Hey again, I am working my way through the book "C++ Primer Fourth Edition". I am trying to run a program out of the book using Microsoft Visual C++ version 6 and I am given the error message: : error C2248: 'hours' : cannot access private member declared in class 'Time' : error C2248: 'minutes' : cannot access private member declared in class 'Time'
12
8501
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too. I, too, am getting nasty FileNotFound exceptions. I've read, and digested the article, and I think I've found a bug -- it's difficult to track, though it does happen often.
0
958
by: Magnus Lundberg | last post by:
Hi, I'm trying to create a XML document looking like this: <?xml version="1.0" encoding="UTF-8"?> <rss> <Header> <FromDate>2006-10-01</FromDate> <ToDate>2007-06-01</ToDate>
9
5759
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just call it Express for simplicity). I have, to try to simplify things, put the exact same DB on two systems, one running MSDE and one running Express. Both have 2 Ghz processors (one Intel, one AMD), both have a decent amount of RAM (Intel system...
1
5123
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from the control unit and store them into the Sql server - The operation console then retrieve this data from the sql for reporting and statistics purposes - I am using ODBC connection - The problem is that the operation console is not able to...
9
3662
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I need your able help in this activity. Objective - In this activity you will design a framework capable of solving any puzzle of a specific type and, as a test of this framework, use the framework to solve a very simple puzzle. In this first...
5
14816
by: jbenner | last post by:
I have opened a PMR for this with IBM, and am not asking for advice from the DB2 DBA community. I am posting this as an FYI that DB2 Health Monitor, even at the latest version of DB2, still can cause huge problems with slow connect times and heavy resource locking in high concurrency / high transaction volume environments. I have an OLTP with 30-90 transactions per second activity, and start of Health Monitor every 2 hours was crashing our...
2
3527
by: violeta123 | last post by:
I am stuck! Please help It might be difficult to explain the problem via email, but I will try. I have a Win 2003 Enterprise server running with the only purpose of a membership web site that uses SQL server 2000 database. I had the site for over 5 years, but the problem started about 6 months ago. At random times (at least I have not found yet any particular time or event when it happens), the Web site Times-out and so the SQL server....
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.