Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

How to Query a Date and Time column

Open Lukeg32-intel opened this issue 3 years ago • 0 comments

def create_query(page_size):
    """
    :type page_size: int
    """

    qry = CamlQuery()
    qry.ViewXml = f"""
    <View Scope='RecursiveAll'>
       <Query><Where><Contains><FieldRef Name='Created'/><Value Type='DateTime'>'2022-08-03T04:00:00Z'</Value></Contains></Where></Query>
       <RowLimit Paged='TRUE'>{page_size}</RowLimit>
   </View>
   """
    return qry

target_list = ctx.web.lists.get_by_title("test123")
list_qry = create_query(50)
items = target_list.get_items(list_qry).execute_query()
print("Loaded items count: {0}".format(len(items)))
for index, item in enumerate(items):  # type: int, ListItem
    print("{0}: {1}".format(index, item.properties['Title']))

I've taken the example code from read_list_via_query.py and tried to query the Created column so I can filter on date and time, but nothing I try returns any rows, I can't find any documentation to see what I'm doing wrong.

I have got it to work on a Yes/No column and a Text column but not for date and time

Lukeg32-intel avatar Sep 03 '22 18:09 Lukeg32-intel