Re: A problem with Time

2007-08-19 Thread Dick Moores
At 08:30 AM 8/16/2007, special_dragonfly wrote:
Hello,

I need to return the date yesterday in the form DDMM. I looked through
the modules: time, datetime and calendar but can't find anything that leaps
out at me.

The problem I'm having is that although I can use time.localtime and get a
tuple of the year, month, day and so forth, I don't believe I can just minus
1 from the day, because I don't think it's cyclic, also, I can't see the
date being linked in with the month.

So is there any way of getting yesterdays date?

The question has already been well-answered, but since I've found 
using the datetime module to be tough going, I was wondering if 
either of these would be easier to understand and use:
1. http://www.egenix.com/products/python/mxBase/mxDateTime/
I see that mxDateTime comes with a 55-page manual as a PDF.

2. http://labix.org/python-dateutil

Dick Moores




-- 
http://mail.python.org/mailman/listinfo/python-list


A problem with Time

2007-08-16 Thread special_dragonfly
Hello,

I need to return the date yesterday in the form DDMM. I looked through 
the modules: time, datetime and calendar but can't find anything that leaps 
out at me.

The problem I'm having is that although I can use time.localtime and get a 
tuple of the year, month, day and so forth, I don't believe I can just minus 
1 from the day, because I don't think it's cyclic, also, I can't see the 
date being linked in with the month.

So is there any way of getting yesterdays date?

Thank You

Dominic 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem with Time

2007-08-16 Thread Shawn Milochik
import time


oneDay = 60 * 60 * 24 #seconds in one day

date = time.time()

yesterday = date - oneDay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem with Time

2007-08-16 Thread syndrowm
On 8/16/07, special_dragonfly [EMAIL PROTECTED] wrote:

 Hello,

 I need to return the date yesterday in the form DDMM. I looked through
 the modules: time, datetime and calendar but can't find anything that
 leaps
 out at me.

 The problem I'm having is that although I can use time.localtime and get a
 tuple of the year, month, day and so forth, I don't believe I can just
 minus
 1 from the day, because I don't think it's cyclic, also, I can't see the
 date being linked in with the month.

 So is there any way of getting yesterdays date?

 Thank You

 Dominic


 --
 http://mail.python.org/mailman/listinfo/python-list


The easiest way I have found, is to use epoch, subtract the length of time,
then convert back to whatever format.  24 hours  is 86400 seconds.

 import time
 time.localtime()
(2007, 8, 16, 9, 41, 28, 3, 228, 1)
 time.localtime(time.time() - 86400)
(2007, 8, 15, 9, 41, 21, 2, 227, 1)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: A problem with Time

2007-08-16 Thread Diez B. Roggisch
special_dragonfly schrieb:
 Hello,
 
 I need to return the date yesterday in the form DDMM. I looked through 
 the modules: time, datetime and calendar but can't find anything that leaps 
 out at me.
 
 The problem I'm having is that although I can use time.localtime and get a 
 tuple of the year, month, day and so forth, I don't believe I can just minus 
 1 from the day, because I don't think it's cyclic, also, I can't see the 
 date being linked in with the month.
 
 So is there any way of getting yesterdays date?

RTFM is the answer...

import datetime
today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)
print yesterday


Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem with Time

2007-08-16 Thread Neil Cerutti
On 2007-08-16, Shawn Milochik [EMAIL PROTECTED] wrote:
 import time


 oneDay = 60 * 60 * 24 #seconds in one day

 date = time.time()

 yesterday = date - oneDay

Or use a timedelta.

 import datetime
 yesterday = datetime.datetime.today() - datetime.timedelta(days=1)
 yesterday.strftime('%m%d%Y')
'08152007'

-- 
Neil Cerutti
It might take a season, it might take half a season, it might take a year.
--Elgin Baylor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem with Time

2007-08-16 Thread Gary Herron
special_dragonfly wrote:
 Hello,

 I need to return the date yesterday in the form DDMM. I looked through 
 the modules: time, datetime and calendar but can't find anything that leaps 
 out at me.

 The problem I'm having is that although I can use time.localtime and get a 
 tuple of the year, month, day and so forth, I don't believe I can just minus 
 1 from the day, because I don't think it's cyclic, also, I can't see the 
 date being linked in with the month.

 So is there any way of getting yesterdays date?

 Thank You

 Dominic 


   
Here's how I'd do it:


 import time
 secondsPerDay = 24*60*60
 today = time.time()
 yesterday = today - secondsPerDay
 print time.strftime(%d%m%Y,time.localtime(today))
16082007
 print time.strftime(%d%m%Y,time.localtime(yesterday))
15082007

Gary Herron


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem with Time

2007-08-16 Thread BartlebyScrivener
On Aug 16, 10:54 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:

 RTFM is the answer...

I don't know. I remember scratching my head for a day or two over the
module explanations and instructions until I found a little howto with
a lot of explicite examples.

http://pleac.sourceforge.net/pleac_python/datesandtimes.html

rd

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem with Time

2007-08-16 Thread MRAB
On Aug 16, 4:30 pm, special_dragonfly [EMAIL PROTECTED]
wrote:
 Hello,

 I need to return the date yesterday in the form DDMM. I looked through
 the modules: time, datetime and calendar but can't find anything that leaps
 out at me.

 The problem I'm having is that although I can use time.localtime and get a
 tuple of the year, month, day and so forth, I don't believe I can just minus
 1 from the day, because I don't think it's cyclic, also, I can't see the
 date being linked in with the month.

 So is there any way of getting yesterdays date?

As well as the other replies, this also works (as far as I can tell!):

import time
today = time.localtime()
yesterday = today[ : 2] + (today[2] - 1, ) + today[3 : ]
yesterday = time.localtime(time.mktime(yesterday))

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem with Time

2007-08-16 Thread Roger Miller
On Aug 16, 9:46 am, MRAB [EMAIL PROTECTED] wrote:

 As well as the other replies, this also works (as far as I can tell!):

 import time
 today = time.localtime()
 yesterday = today[ : 2] + (today[2] - 1, ) + today[3 : ]
 yesterday = time.localtime(time.mktime(yesterday))

This is something I have wondered about.  The C library mktime
function is
documented to fix up out of range values,.  For example July 32
becomes
August 1 and August -1 becomes July 31.  Python presumably inherits
this
very useful (and seemingly not well known) behavior, but it is not
documented.  Is this just an oversight, or is it intentional on the
grounds
that it might be platform-dependent?  Any language lawyers out there
that
would care to comment?

-- 
http://mail.python.org/mailman/listinfo/python-list


Freeze problem(second time do not imported)

2007-03-28 Thread dyp
Hi,

I am using DLLs from freez.py  and these dll are running inside a
program(Not OS level). If I have 2 dlls such as A.dll, B.dll,
I can import and run a(A.run()) function in  A.dl,
next I can import and run a function(B.run()) in B.dll
Next if I try to run A.run(), it doesn't work at all.

Anyone knows what is the reason and tips?

Thanks in advance!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with time

2007-03-23 Thread ian

Steve Holden [EMAIL PROTECTED] a écrit dans le message de news:
[EMAIL PROTECTED]
 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 :)


-- 
http://mail.python.org/mailman/listinfo/python-list

Problem with time

2007-03-22 Thread 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.timedelta' (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


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with time

2007-03-22 Thread Michael Bentley

 1) i got 2 values from mysql db (fields are time type)
 2) python get it as type 'datetime.timedelta' (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.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with time

2007-03-22 Thread Steve Holden
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.timedelta' (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.timedelta 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

-- 
http://mail.python.org/mailman/listinfo/python-list


problem with time

2005-03-08 Thread a_geek
Hello,

I'm writing a small program that needs to check Unix timestamps for
falling into an interval (typical usage: ./program 2005-03, you get
the idea). Now, I create two time stamps from the user's input to
create the interval's borders using mktime(). Trying to check the sanity
of my program, I also converted the values back to tuples using
localtime(). Unfortunately, I get back one of them with the DST flag
set, and the other with the DST flag unset.

I have _no_ idea on how localtime() could reasonably synthesize
different values for that flag for _any_ time value converted in about
the same millisecond. What gives?

Thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list