Google Analytics API for dateRange of previous month

584 views Asked by At

We are reading the Google Analytics data using Cozyroc REST Source component in SSIS package. While reading the data, I can add the dateRange startDate and endDate in 'YYYY-MM-DD' format. Instead of adding static values, I wanted to read the data for 1st date to last date of previous month. As I see, there is nthdayago field. But how I can achieve the dateRange of previous month dynamically ?

2

There are 2 answers

0
Michele Pisani On

The only relative dates expressions are today, yesterday or NdaysAgo, so you have to create a custom formula in your system to go back to the length of the previous month.

2
KeithL On

Assuming you can take variables:

@LastMonth = dateadd("m",-1,getdate())
@LastMonthDay1 = (DT_DATE) ( (DT_WSTR,2)Month(@LastMonth) + "/1/"  + (DT_WSTR,4) year(@LastMonth)) 
@LastMonthLastDay = dateadd("d",-1,dateadd("m",1,@LastMonthDay1))