Assuming the reference field in the input data has a data type of datetime, you can use the following script in a Transform node to filter the required records.
Note, change the input field reference in the ProcessRecords Script (fields.test_Datetime in the example)
#### Start of ConfigureFields Script:
#Configure all fields from input 'in1' to be mapped
#to the corresponding fields on the output 'out1'
out1 += in1
## Debug fields
## Create a date-type field to display today's datetime
out1.Current_Datetime = datetime.datetime
## Create a date-type field to display the datetime one week ago
out1.One_Week_Ago = datetime.datetime
## End Debug fields
## Create a variable with today's date
today = datetime.date.today()
## Specify the time as the start of the day
start_Of_Day = datetime.time(00, 00, 00)
## Combine the date and time elements to form a datetime object
start_Of_Today = datetime.datetime.combine(today, start_Of_Day)
## Create a timedelta variable that represents a period of 7 days
one_Week_Period = datetime.timedelta(days=7)
## Calculate the datetime 7 days ago
Datetime_one_week_Ago = start_Of_Today - one_Week_Period
#### End of ConfigureFields Script:
#### Start of ProcessRecords Script:
## Selectively output records if they are recent enough
if fields.test_Datetime >= Datetime_one_week_Ago:
out1 += in1
## Debug output fields
out1.Current_Datetime = start_Of_Today
out1.One_Week_Ago = Datetime_one_week_Ago
## End Debug output fields
## Write the record
node.write(0, out1)
End of ProcessRecords Script:
You may also be interested in some of the examples in the Help documentation relating to Python scripting for datetime data types. See the following topic in your system's integrated Help documentation:
Data360 Analyze Server Help > Migrating from LAE > What's changed? > BRAINscript to Python > Date, time and datetime functions
The information is also available online for the latest version of the product here:
https://help.precisely.com/r/Data360-Analyze/3.14/en-US/Data360-Analyze-Server-Help/Migrating-from-LAE/What-s-changed/BRAINscript-to-Python/Date-time-and-datetime-functions
------------------------------
Adrian Williams
Precisely Software Inc.
------------------------------
Original Message:
Sent: 05-26-2024 22:12
From: Nathan Schofield
Subject: Filter Results for Last 7 Days
Hi - Im trying to only show results from the last 7 days, from a dataset that goes back years. In the Filter node, the only options within Operator and Value ask for a specific date. Is there a different node or example scripting i could use to achieve this?
------------------------------
Nathan Schofield
Telstra Corporation Limited
Sydney NSW
------------------------------