Python Forum

Full Version: Unable to pass date timestamp as Parameters :
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Team ,

Need small help .. I just want to pass time stamps for end and start . How can I do this in below code
could you please help me with this

For example
Start as todays morning 09:15 AM
and end as current time stamp

tech_list = ['AAPL','GOOG','MSFT','AMZN']
end = datetime.now()
start = datetime(end.year - 1,end.month,end.day)
for stock in tech_list:   
    # Set DataFrame as the Stock Ticker
    globals()[stock] = DataReader(stock,'yahoo',start,end)
you can use time to get start and end time (run once before starting process, once after then subtract difference)
Or a better approach would be to use time.process_time
example
from time import process_time 

def fibo(n):
   if n <= 1:
       return n
   else:
       return(fibo(n-1) + fibo(n-2))

start_time = process_time()  
print(f"\nStarting process at: {start_time}")  

# pass some time
for x in range (30):
    print(f"{fibo(x)} ", end ='')

stop_time = process_time()

print(f"\nTotal time: {stop_time - start_time} seconds.\n")
output of above:
Output:
Starting process at: 0.01270591 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 Total time: 0.35556174 seconds.