I have a file sorted per date / time in csv form, eg below, upon which I am making calculations. I want my code to cease calcs for that day once a certain time has passed. eg, no more calc if Time > 20:00. the time every day does not change. Data example:
Date Time Open High Low Close Volume
02/01/2015 14:30:00 111.39 111.44 111.2 111.24 707185
02/01/2015 14:31:00 111.24 111.3 111.14 111.3 286506
I have tried to define an endTime, then I say when time > endTime... suggestions appreciated..
endTime = datetime(int(datetime.now()), int(datetime.now()), int(datetime.now()), 15, 30, 00)
TypeError: int() argument must be a string or a number, not 'datetime.datetime'
endTime = datetime.time(hour=20, minute=00, second=00)
TypeError: descriptor 'time' of 'datetime.datetime' object needs an argumen
Python library defines a function that can be primarily used to get current time and date. now() function Return the current local date and time, which is defined under datetime module. Parameters : tz : Specified time zone of which current time and date is required.
Use datetime. strftime(format) to convert a datetime object into a string as per the corresponding format . The format codes are standard directives for mentioning in which format you want to represent datetime. For example, the %d-%m-%Y %H:%M:%S codes convert date to dd-mm-yyyy hh:mm:ss format.
Date and datetime are an object in Python, so when you manipulate them, you are actually manipulating objects and not string or timestamps.
To create a time object, we use the time class in the datetime module using the statement, datetime. time(hour, minutes, seconds), where hour is the hour, minutes is the minutes, and seconds is the seconds.
class datetime.datetime
A combination of a date and a time. Attributes: year, month, day, hour, minute, second, microsecond, and tzinfo.
>>> import datetime
>>> endDateTime = datetime.datetime(2015, 2, 1, 14, 30, 00)
>>> endDate = datetime.date(2015, 2, 1)
>>> endTime = datetime.time(14, 30, 00)
>>> now = datetime.datetime.now()
>>> endTime = datetime.datetime(now.year, now.month, now.day, now.hour, now.minute, now.second)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With