Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Finding if the get_datetime() is a Monday

Hi,

Could you show me how I calculate and detect if the get_datetime() object is a Monday please. I've so far been unsuccessful.

Thanks,
Andrew

3 responses
import datetime

date = datetime.datetime(2014, 11, 5)  
# Monday = 0, ... Sunday = 6  
day = date.weekday()  
isTodayMonday = day == 0  
print isTodayMonday  

Thank you Mete! I was trying along lines of this but didn't find the right way of doing it. That helps greatly

-Andrew

Day of week without import and using a single line:

def initialize(context):  
    context.stocks = symbols('TSLA')

def handle_data(context, data):  
    # Prints day of week as integer, 0 for Monday, 1 for Tuesday etc  
    print data[context.stocks[0]].datetime.weekday()  
    #   (weekday() is available inside any one of the sids)

    # Day of month  
    #print data[context.stocks[0]].dt.day