How to specify a date range for the Google Adwords CLICK_PERFORMANCE_REPORT - google-ads-api

I am trying to query the adwords api (v201603) and am using/extending the Java examples provided.
The problem I am encountering is being able to specify a specific date to download the report data for the CLICK_PERFORMANCE_REPORT report. This report is restricted to returning a single days worth of data at a time (for up to the last 90 days).
I can get todays and yesterdays data using the specifiers : ReportDefinitionDateRangeType.TODAY and ReportDefinitionDateRangeType.YESTERDAY, but what I really need to do is be able to specify a specific date within the last 90 days in order to get as much historical data as possible.
I have tried the following:
DateRange dr = new DateRange();
dr.setMin("20160401");
dr.setMax("20160402");
selector.setDateRange(dr);
reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.CUSTOM_DATE);
reportDefinition.setReportType(ReportDefinitionReportType.CLICK_PERFORMANCE_REPORT);
reportDefinition.setDownloadFormat(DownloadFormat.CSV);
Both with and without the custom date specifier - and either gives the following error:
Report was not downloaded due to: HTTP Response Code: 400, Trigger: A single day DateRange is required for reportType: CLICK_PERFORMANCE_REPORT, Type: ReportDefinitionError.INVALID_DATE_RANGE_FOR_REPORT
Any help much appreciated, thanks in advance

You're going to have to use DURING and the same date string.
... + 'DURING 20161004,20161004';

Single Day Iterator for AdWords Scripts CLICK_PERFORMANCE_REPORT:
var start = new Date("12/01/2016");
var end = new Date("12/18/2016");
while(start < end){
var newDate = start.setDate(start.getDate() + 1);
start = new Date(newDate);
singleDay = start.toISOString().substring(0, 10).replace(/-/g,"");
console.log(singleDay);
}
Utilities.formatDate(start, timeZone, "yyyyMMdd"); formats date object as an 8-digit integer, so:
singleDay = Utilities.formatDate(start, timeZone, "yyyyMMdd");
Use singleDay in 'DURING ' + singleDay + ',' + singleDay);
Working with Dates and Times #Reporting — AdWords Scripts

Related

What type of date format is this? And how to convert it?

I found strange date codes in a SQL database used by an old iOS app called Memo Lite. The column was labeled LMT, that might be an abbreviation for last modified time. How are they constructed and how can they be converted to readable formats, like yyyy-mm-dd HH:mm:ss?
I am aware of both Unix time and how Google Sheets handles time.
Example of date/time codes:
357931095.942149 = 2012-05-05
330432567.859129 = 2011-06-22
293964817.803674 = 2010-04-26
I don't know if the format has time, it looks so but it is not showed in the app.
Date/time format codes, reference example:
https://support.google.com/docs/answer/3094139?hl=en
A little math shows it's seconds since an epoch. Not the usual 1970-01-01, but 2001-01-01.
2001-01-01 + 293964817 seconds = 2010-04-25 08:53:37
2001-01-01 + 330432567 seconds = 2011-06-22 10:49:27
2001-01-01 + 357931095 seconds = 2012-05-05 17:18:15
The decimal portion is microseconds. For example, 293964817.803674 is 2010-04-25 08:53:37.803674.
You mentioned it's an iOS app, so it's likely CFAbsoluteTime.

How to get Date as a segment in Final_URL_Report in Adwords API

Executing my code (using the Google Adwords Library to build an oauth user etc) works when using a query with Month as a segment
String query = "SELECT EffectiveFinalUrl, Cost, Clicks, Impressions,
Month FROM FINAL_URL_REPORT";
But it aggregates across all time, split into months. I am trying to pull in the data as daily aggregates. The documentation has both Month and Date (splitting data into yyyy-MM-dd) as a segment you can include in the query, but Date does not work.
String query = "SELECT EffectiveFinalUrl, Cost, Clicks, Impressions,
Date FROM FINAL_URL_REPORT";
Results in Error 400: Bad Request.
Am I missing something in the documentation that tells me how to resolve this?
Adwords Final_URL_Report Documentation
Try set a date range by adding something like DURING ... to your query.

Timezone Offset in Angular JS and Rails

Background: I'm building an app with Angular JS as web interface and Rails API. The problem I am having is passing a date from Angular to Rails.
Issue: I have a form with a Date of Birth date field, when a user inputs his DOB say March 1st, 1985, Angular interprets it as 1985-03-01 00:00 +0800 (if you're in Hong Kong or Singapore) and sends a request to Rails. The first thing Rails does with it is to convert it to UTC, which means the datetime is now 1985-02-28 16:00 UTC. Therefore, when the date is saved to the database date column, it becomes Feb 28, 1985.
Solution for now: What I'm doing now is on Angular side, I get the Timezone offset hours and add it to the date, so instead of 1985-03-01 00:00 +0800, it is now 1985-03-01 08:00 +0800. When Rails get it, it converts to 1985-03-01 00:00 UTC and so saves the correct date to db. However, I believe this is a better alternative to tackle this issue.
Thinking about parsing just the date in Rails, yet the params[:dob] I see is already UTC by the time I get it. Would love to know if there is a better practice than my current solution. Thank you for any comment and feedback.
This problem is actually quite common, and stems from two separate but related issues:
The JavaScript Date object is misnamed. It's really a date + time object.
The JavaScript Date object always takes on the characteristics of the time zone for the environment in which it is running in.
For a date-only value like date-of-birth, the best solution to this problem is to not send a full timestamp to your server. Send just the date portion instead.
First, add 12 hours to the time, to use noon instead of midnight. This is to avoid issues with daylight saving time in time zones like Brazil, where the transition occurs right at midnight. (Otherwise, you may run into edge cases where the DOB comes out a day early.)
Then output the date portion of the value, as a string in ISO format (YYYY-MM-DD).
Example:
var dt = // whatever Date object you get from the control
dt.setHours(dt.getHours() + 12); // adjust to noon
var pad = function(n) { return (n < 10 ? '0' : '') + n; }
var dob = dt.getFullYear() + '-' + pad(dt.getMonth()+1) + '-' + pad(dt.getDate());
Another common way to do this is:
var dt = // whatever Date object you get from the control
dt.setHours(dt.getHours() + 12); // adjust to noon
dt.setMinutes(dt.getMinutes() - dt.getTimezoneOffset()); // adjust for the time zone
var dob = dt.toISOString().substring(0,10); // just get the date portion
On the Rails side of things, use a Date object instead of a DateTime. Unlike JavaScript, the Rails Date object is a date-only object - which is perfect for a date-of-birth.

grails ORM , how to search Date without time

I am using postrges db.
My domain has a date field:
java.util.Date requestedDate;
I am trying to search by date in my controller:
eq ("requestedDate", requestedDate)
This works fine, but the problem is that date and time has to be exactly matching for this. But in application the user will only enter the date to search items (like give me all requests which are made on 2014-02-05 and the browser application will add the current time to the request). So the comparison fails because the user entered time is different from the time during creation of the request.
I tried 'like' but it throws error.
How to compare only date part ?
You could do something like this:
Date now = new Date()
now.clearTime()
def results = Meeting.withCriteria {
between('date', now, now+1)
}
So this strips off the time portion of the current date, and then does a 'between' query (between midnight just gone and midnight 24 hours later).
Still it looks like there is no convenient way to realize this.
You need a small detour by computing the start of the day and the end of the day and use the between operator.
EDIT
I just saw now rcgeorge23 gave you the right example for doing this.

OData: Date "Greater Than" filter

Is there a way to return a series of records in OData by specifying a "Date greater than xxxxx" filter...but using a Date that was previously obtained form an OData feed?
Use Case: Pretend that I want to build a web page that displays a list of the most recently completed online orders. This is what I'm aiming for:
Load the page
Hit my OData service asynchronously, returning the last 100 orders (ordering by date descending so that the most recently completed order shows up first)
Build the HTML on the page using the OData data
Store the MAX date into a global variable (looks like this: /Date(1338336000000)/)
Hit the OData service on a 30 second interval but this time specify a filter to only return records where the order date is greater than the previous MAX Date. In this case: /Date(1338336000000)/
If any records are returned, build the HTML for those records and prepend the items to the previously loaded items.
Where I am struggling is in specifying the Date "greater than" filter. For some reason, the date filters in OData do not seem to play very nice with OData's own native date format. Do I need to convert the date originally obtained into a different format that can be used for filtering?
I want to do something like this:
http://mydomain/Services/v001.svc/Orders?$filter=close_dt%20gt%201338336000000
FYI: I'm using V2
Figured this out.
OData V2 out-of-the-box returns dates out of SQL in JSON Date format like so:
/Date(1338282808000)/
However, in order to use a date as a filter within an OData call, your date has to be in EDM format, looking like this:
2012-05-29T09:13:28
So, I needed to get the date from my initial OData call, then convert it to the EDM format for use in my subsequent OData calls, which look like this:
/Services/v001.svc/Orders?$filter=close_dt gt DateTime'2012-05-29T09:13:28'
I ended up creating a javascript function that does the formatting switcharoo:
function convertJSONDate(jsonDate, returnFormat) {
var myDate = new Date(jsonDate.match(/\d+/)[0] * 1);
myDate.add(4).hours(); //using {date.format.js} to add time to compensate for timezone offset
return myDate.format(returnFormat); //using {date.format.js} plugin to format :: EDM FORMAT='yyyy-MM-ddTHH:mm:ss'
}
A couple of notes:
The JSON format does not seem to adjust for timezone, so the date returned does not match the date I see in my database. So I had to add time manually to compensate (someone please explain this).
I am using the date.format.js plugin which you can download here for formatting the date and adding time.
In OData V4 date filtering format has changed to $filter=close_dt gt 2006-12-30T23:59:59.99Z
For example
http://services.odata.org/V4/OData/OData.svc/Products?$filter=ReleaseDate%20gt%202006-12-30T23:59:59.99Z
For previous versions of OData see previous answers
If you use the datetime logic, you can do lt or gt.
e.g.
...mydomain/Services/v001.svc/Orders?$filter=close_dt gt datetime'20141231'
Just an FYI: in V3 of the protocol the non-tick-based datetime format is now the default:
http://services.odata.org/Experimental/OData/OData.svc/Products%280%29?$format=application/json;odata=verbose&$select=ReleaseDate
..."ReleaseDate":"1992-01-01T00:00:00"...
I will just try to make the answer of #avitenberg more clear:
var date= DateTime.Now;
//Convert time to UTC format
$"filter={close_dt} gt {date:yyyy-MM-ddTHH:mm:ss.FFFZ}";
See Microsoft:

Resources