ROLLING date range in a Google Ads API Query - google-ads-api

let startDate = '2020-01-01';
let endDate = new Date().toISOString().slice(0, 10).toString();
//
"WHERE segments.date BETWEEN '2020-01-01' AND 'endDate' "
Returns this error:
Exception: Call to GoogleAdsService.Search failed: Condition
'segments.date BETWEEN '2020-01-01' and 'endDate'' is invalid: BETWEEN
operator must have exactly two values that are both numbers or both
date strings in 'YYYY-MM-DD' format.
How can I set endDate to YESTERDAY?

Google Ads Query Language accepts dates both with and without quotes. If you use the ISO-like date format with hyphens, quotes are mandatory, though.
Assuming that this is JavaScript, you can just do
"WHERE segments.date BETWEEN '2020-01-01' AND '" + endDate + "'"
Or using template literals (available from ES6 on, note the enclosing backticks):
`WHERE segments.date BETWEEN '2020-01-01' AND '${endDate}'`

Try using: WHERE segments.date BETWEEN '2020-01-01' AND endDate
instead of WHERE segments.date BETWEEN '2020-01-01' AND 'endDate'

Related

Tableau Convert Date to first date of the month

How can I convert any date to first of the month in tableau while retaining month as 2 digits and
format as date?
I have tried
INT("01" + "-" + STR(MONTH([Date])) + "-" + STR(YEAR(Date))) which returns month as single digit
Date
Converted Date
9/01/2020
1/01/2020
10/01/2020
1/01/2020
5/03/2021
1/03/2021
12/03/2021
1/03/2021
You can create a calculated field like this:
MAKEDATE(YEAR([Date]),MONTH([Date]),1)
If you're using a live connection, it all depends on the source you're connecting to.
You can also try:
date(
right('0'+str(month([Order Date])),2)
+
'01'
+
str(year([Order Date]))
)
Just remember to right-click your CF --> Default Properties --> Date Format
You should get something like this:

get the next date based on frequency set using google sheet formula

I need to display the upcomind date based on the start date and frequency set.
I have tried with
=TODAY() + MOD(TODAY() - C2, F2)
Here is the sheet
Could try:
G2 + F$2-MOD(G2 - C$2, F$2)
where G2 is today's date
Answer:
The upcoming date is given by:
=((((((C2-DATE(1970,1,1))*86400)+(((D2-DATE(1970,1,1))*86400)-((C2-DATE(1970,1,1))*86400))/H2)/60)/60)/24)+DATE(1970,1,1)
This is equivalent to:
(end date) - (start date)
(start date) + ___________________________
(frequency)
Where each date is converted to a unix timestamp for calculation and converted back to date format for display.
Remember that frequency will have to be decremented when each upcoming date passes in order to update the formula to the new upcoming date.
References:
DATE - Docs Editors Help
Unix Time - Wikipedia

Combining Date variables in SPSS

I get a raw data file that has two fields: Start_Date and Start_Time. They are initially String variables, where Start_Date is in MM/DD/YYYY and Start_Time is in hh:mm:ss formats.
I'd like to combine these into a single Date variable (MM/DD/YYY hh:mm:ss). Here is the syntax I'm using but it's clumsy:
String MyDate(A20).
Compute MyDate = Concat(CHAR.SUBSTR
(Start_Date, 4, 2), '-', CHAR.SUBSTR (Start_Date, 1,2), '-',
CHAR.SUBSTR (Start_Date, 7,4), ' ', Start_Time).
Execute.
Alter Type MyDate (DATETIME20).
Execute.
Creating some example data:
data list list/Start_Date Start_Time (2a10).
begin data
"09/18/2018" "18:15:13"
end data.
Now use the following syntax to combine the two texts into one date-time variable:
compute StartDT=sum(number(Start_Date, adate10), number(Start_Time, time8)).
formats StartDT (datetime20).

How to automatically format NOW() in to a string that that displays YYYY-MM-DD?

Is it possible to format the output of NOW() to a string that displays YYYY-MM-DD?
This is the output of NOW(): 29/02/2012 12.07.37
The reason is, that I need to use the current date in a QUERY.
QUERY only accepts date in the format YYYY-MM-DD . I can't get a date directly from a cell, because it gets formatted as (even if I change the formatting): DD/MM/YYYY
Perhaps some regular expression?
If this is supposed to be an in-cell formula then you can use
=TEXT(NOW(),"yyyy-mm-dd")
I will follow JMax's suggestion and convert my comment to an answer.
Now() returns the current date and time as a number. The integer part gives the date and the fraction part gives the time. If you print or display that date, the default is to give the full date in what Microsoft think's is the local format.
Format(expn, fmt) allows you to convert an expression to a string. For example:
Dim DateStg as String
DateStg = Format(Now(),"yyyy-mm-dd")
fmt defines the format to which the expn is to be converted. fmt is a mixture of code letters (such as: "yyyy", "mm", "dd") and punctuation (such as "-"). "yyyy-mm-dd" appears to meet your current needs but you can also usethe following to format dates:
"mmm" to give three letter month (Jan, Feb, etc.)
"mmmm" to give full name of month (January, February, etc)
"ddd" to give three letter day of week (Mon, Tue, etc)
"dddd" to give full name of day of week (Monday, Tuesday, etc)
In VB.net you can do the following:
Dim dateStr As String = Now().ToString("yyyy-MM-dd")
In C# you can do it like this:
String dateStr = DateTime.Now.ToString("yyyy-MM-dd");

To_Char function in Oracle ,giving an error for alias?

This is the command,i am using in ORACLE 9i.
SELECT TO_CHAR(SYSDATE,'DD-MON-YYYY') Date FROM DUAL;
It gives an error "FROM keyword not found,Expected" ,where Date is an ALIAS,but when i enclosed
Date in "Date" double quotes like this ,it is taking it as an Alias and output is right.
Please SUGGEST!!!
Probably caused because Date is a reserved word in Oracle,
SELECT *
FROM v$reserved_words
where keyword = 'DATE'
Putting the '' around it "escapes" it so it can be used.
Use this:
SELECT TO_CHAR(SYSDATE,'DD-MON-YYYY') INTO Date FROM DUAL;

Resources