Python automatic date?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2008
Posts: 18
Reputation: JA5ONS is an unknown quantity at this point 
Solved Threads: 0
JA5ONS JA5ONS is offline Offline
Newbie Poster

Python automatic date?

 
0
  #1
Jun 4th, 2008
just wondering if there is anything in python to give the date automaticly, just like excel has =today()

cheers.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 908
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 145
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Python automatic date?

 
0
  #2
Jun 4th, 2008
You should try using the time module
  1. import time
  2. print time.localtime()
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 18
Reputation: JA5ONS is an unknown quantity at this point 
Solved Threads: 0
JA5ONS JA5ONS is offline Offline
Newbie Poster

Re: Python automatic date?

 
0
  #3
Jun 4th, 2008
cheers mate.

it gives me a returen of
"(2008, 6, 4, 19, 11, 46, 2, 156, 0)"
which is Year, month, day, hour, min, seconds, something, something, someting
how do i get only 24hour time, so i can get 19.11
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 908
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 145
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Python automatic date?

 
0
  #4
Jun 4th, 2008
you can use the following code:
  1. time.localtime()[3:5]
that just gives the hour and the minutes
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 18
Reputation: JA5ONS is an unknown quantity at this point 
Solved Threads: 0
JA5ONS JA5ONS is offline Offline
Newbie Poster

Re: Python automatic date?

 
0
  #5
Jun 4th, 2008
mate your a legend.
is it possibe to subtract one time from another?

i want to say,
19 , 32 take 19, 22
and it will leave me with the answer
10

mate i appreciate it.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 908
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 145
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Python automatic date?

 
0
  #6
Jun 4th, 2008
you could do it by making it into the amount of minutes. This way you can make sure it stays base 60
TO get the difference in minutes:
  1. g = time.localtime()[3:5]
  2. f = time.localtime()[3:5]
  3. m = g[0]*60+g[1]
  4. n = f[0]*60+f[1]
  5. print n-m
to make it back into hours and minutes:
  1. g = time.localtime()[3:5]
  2. f = time.localtime()[3:5]
  3. m = g[0]*60+g[1]
  4. n = f[0]*60+f[1]
  5. g=n-m
  6. hours = g/60
  7. g=g-hours*60
  8. mn = g
  9. print hours,":",mn
I think that works
Last edited by Paul Thompson; Jun 4th, 2008 at 6:45 am. Reason: used keyword as variable
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 18
Reputation: JA5ONS is an unknown quantity at this point 
Solved Threads: 0
JA5ONS JA5ONS is offline Offline
Newbie Poster

Re: Python automatic date?

 
0
  #7
Jun 4th, 2008
LEGEND!!!
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 908
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 145
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Python automatic date?

 
0
  #8
Jun 4th, 2008
no worries
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 18
Reputation: JA5ONS is an unknown quantity at this point 
Solved Threads: 0
JA5ONS JA5ONS is offline Offline
Newbie Poster

Re: Python automatic date?

 
0
  #9
Jun 4th, 2008
got another one for ya mate.
same thing but for the date? to give me dd/mm/yy?
same as =today() in excel.
cheers.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 18
Reputation: JA5ONS is an unknown quantity at this point 
Solved Threads: 0
JA5ONS JA5ONS is offline Offline
Newbie Poster

Re: Python automatic date?

 
0
  #10
Jun 4th, 2008
well im at it.
sorry to be a pain, but still learning.. and loving it, your helping majorly!!

i have two more issues, and than i've finished it.
how can i make it, instead of "press enter to exit" that you press enter to go back to the top of the program and run again?
cheers again!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC