Dynamically change the date in segments.date section

53 views
Skip to first unread message

Rishi Kumar

unread,
Feb 14, 2024, 3:54:14 AM2/14/24
to Google Ads API and AdWords API Forum
Hey, 

I'm facing issue in updating the end date in segments.date section of the below query, but unable to findout the solution, can anybody help me.

"SELECT campaign.name, metrics.cost_micros, metrics.clicks, metrics.impressions, metrics.ctr, metrics.conversions, metrics.conversions_value FROM campaign WHERE segments.date >= '2023-11-01' AND segments.date <=  'end_date'  ");

Google Ads API Forum Advisor

unread,
Feb 14, 2024, 7:57:20 AM2/14/24
to ri...@upila.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads API support team. 

By reviewing your concern, I understand that you are facing issue in updating the end date in segments.date and you are looking for guidance to resolve this issue. Kindly note that filtering conditions on the "segments.date" field using the "<=" operator must contain an operand that takes the format of a date formatted as "YYYY-MM-DD". I would recommend you to kindly refer to the "Google Ads Query Language Grammar" documentation for more information. Also, I would suggest you to refer to the "Date Ranges" guide while querying with the date segments. You can also refer to the "Predefined date range" where you cannot find the 'end_date' field which you are using in your API query. So I would request you to pass the custom date in place of "end_end" in your GAQL query. You can even include the "DURING" operator while segmenting with the date. Please find the sample GAQL query for your requirement:
SELECT campaign.name, metrics.cost_micros, metrics.clicks, metrics.impressions, metrics.ctr, 
metrics.conversions, metrics.conversions_value FROM campaign WHERE segments.date >= 
'2023-11-01' AND segments.date <=  '2023-11-30'

or 

SELECT campaign.name, metrics.cost_micros, metrics.clicks, metrics.impressions, 
metrics.ctr, metrics.conversions, metrics.conversions_value FROM campaign WHERE segments.date
DURING LAST_30_DAYS

Additionally, I would suggest you to utilize the Google Ads Query Builder and Query Validator to build and validate the queries for retrieving the data from the Google Ads API. 

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rz6E2:ref"

Thanks,
 
Google Logo Google Ads API Team


Reply all
Reply to author
Forward
0 new messages