How to work with raw date format in Google Sheets - google-sheets

I'm using Zapier to input timestamps of emails to Google Sheets. The format I'm seeing in Google Sheets is:
Wed, 28 Jun 2017 21:02:51 +0000 (UTC)
Is there a way to either change this (in Google Sheets) to 2017-06-28 21:02:51 or to help date-related functions to understand this format?

You should be able to extract date from string:
=DATEVALUE(REGEXEXTRACT("Wed, 28 Jun 2017 21:02:51 +0000 (UTC)","\d+ [A-Za-z]{3} \d{4}"))
REGEXEXTRACT part extracts "28 Jun 2017". Then format the result as date.
Edit:
Getting closer :) Error DATEVALUE parameter '28 Jun 2017' cannot be
parsed to date/time.
I think this is bacause of your regional settings.
Option: writing script, my solution wont work.
Option: Change File → Regional Settings to US.
Option: modify the formula so it replaces english names of monthes into their numbers. This would produce ugly big formula.

Related

Query function behaving strange with dates in google sheets

Function which isn't working: =QUERY(A:B, "SELECT A WHERE B > " & D1, 0)
What it's looking at:
A
B
Strings
13 Feb 2023
Strings
18 Feb 2023
Strings
21 Feb 2023
Cell D1 =
10 Feb 2023
Trouble shooting:
The query is coming up no results. All dates are numbers, when I format them as numbers instead of dates it works, when I format them as DD MMM, it works, but when I format them as DD MMM YYYY it doesn't work and this is the format I need it in.
Question
Why is Query so sensitive to date formats?? I always use different date formats depending on the sheet and vlookup has no issue with this. Also why on earth would it just not accept one format? I really want to learn for future
for query you may use:
=QUERY(A:B, "SELECT A WHERE B > date'"&text(D1,"yyyy-mm-dd")&"'")
if you wish to avoid the query confusion; you may just go with simple filter Fx
=filter(A:A,B:B>D1)

What means "Invalid date specified" on querying of Google Analytics API

I query Google Analytics API from outta Google Sheets.
My endDate I define in B2 as =today(), my startDate I define in B3 as =B2-30.
B2 and B3 cells I formatted manually as date in yyyy-mm-dd format.
On running a query I get an error:
{ "error": { "code": 400, "message": "Invalid Date specified: Wed Oct 27 2021 00:00:00 GMT+0200 (CEST)", "status": "INVALID_ARGUMENT" } }
What is wrong with my date input?
I have one guess, my dates from B2 and B3 are transmitted to API instead of format mm/dd/yyyy in the format Wed Oct 27 2021 00:00:00 GMT+0200 (CEST). If my guess is correct, how can I turn dates into the right format?
To use dates coming from formula like =today() and derivative calculations it doesn't help to re-format values as dates manually, using GSheets formatting function, as I tried it before.
The way I worked it successfully out, is to explicitly make a text from values while formatting it to the needs, like it explained in the according documentation:
=TEXT(TODAY(),"yyyy-mm-dd") and =TEXT(B2-30,"yyyy-mm-dd")

Filter dates December text format D Google Sheets

I have a column of dates that I want to convert to the following format below:
Oct 1,5,10,12,18,19,26,27,28,29,30
Nov 2,3,4,9,17,18
Dec 3,22,23,24,25,26,27,28,29,30,31,30,30,30,30,30,30,30,30,30
Jan 1,2,3,4,5,6,16,18,19,26
Feb 2,9
Mar 2,8,9,10,23
Apr 13,19,20,21,22,27
I'm using e.g.
=join(",",(filter(text($H$38:$H$204,"d"),month($H$38:$H$204)=10)))
where $H$38:$H$204 refers to the dates to produce the days for October and other months which all work fine with the exception of December (12) which produces repetitive 30 at the end.
It's bizarre behaviour and I can't work it out.
ok got it thanks.
if the array has blank cells at the end it seems to produce this behaviour.
Use:
=join(",",(filter(text($H$38:$H$204,"d"),$H$38:$H$204<>"",month($H$38:$H$204)=12))) to filter out blank cells also.
Still bizarre it seems to happen for only one month.
Regards

Google Spread Sheet Script. Working with Dates

I am reading list of Google Sheet cells containing DateTime, using Google Apps Script.
The values in the cells are:
A1: Jul 26 13:00
A2: Jul 27 0:00
var dateValues = SpreadsheetApp.getActiveSheet().getRange("A1:A2").getValues();
However, values read are 1 hour behind. This is what I see in the debugger:
dateValues[0] = Wed Jul 26 2017 12:00:00 GMT+0200 (EET)
dateValues[1] = Wed Jul 26 2017 23:00:00 GMT+0200 (EET)
I guess this is a time zone issue, but I don't really understand the concept.
My time zone is currently (due to DTS) GMT + 3. Indeed, outside the DTS period it is GMT +2. The spread sheet time zone is Jerusalem GMT+2.
EET - don't underrated why it is being used.
Basically, I would expect to get in code the values with in the sheet.
What is the concept?
there are two ways to solved this
Use getDisplayValues() rather than getValues(). This will force to do some conversions, as getDisplayValues() returns strings not dates
make you script editor time zone match the sheet tz.
In my case the sheet was (GMT+2 Jerusalem), but the script editor was different (GMT+2 Moscow) for some reason.
Setting the script editor TZ, solved the problem.

Parse a date string from a twitter post with timezone info included

I have created a tweet using Twitters REST API. The returned JSON from Twitter from the created Tweet is in this format
'Tue Jan 31 11:15:15 +0000 2017'
Darts
DateTime.parse('Tue Jan 31 11:15:15 +0000 2017');
won't parse this format. I turned to the intl package holds some hope in dealing with this. I try to use DateFormat to solve this thus
DateFormat format = new DateFormat("EEE MMM dd HH:mm:ss ZZZZ yyyy");
format.parse('Tue Jan 31 11:15:15 +0000 2017');
It fails. The only way I can get it to work is to remove the timezone part of the twitter date string
'Tue Jan 31 11:15:15 2017'
and do the following
var date = 'Tue Jan 31 11:15:15 +0000 2017'.split(' ');
date.removeAt(4);
DateFormat format = new DateFormat("EEE MMM dd HH:mm:ss yyyy");
format.parse(date.join(' '));
How can I parse a Twitter datetime string without removing the timezone info part?
It looks like package:intl doesn't support timezones yet: https://github.com/dart-lang/intl/issues/128
You could add your use case to the issue (it shouldn't be much work or require extra data to support the 'ZZZZ' case, since you just need to parse a number), or even better, submit a Pull Request!
Dart DateTime doesn't support timezones, so it's not that useful to parse them. Also, Intl is probably not the best way to parse a string like this. The point of Intl date parsing is that it varies by locale. If you want to parse a fixed format it can be done more easily and more efficiently.
Since DateTime doesn't support time zones, if you want to use that information, it seems like your best bet is to remove it, get the information, and then add that to the time after the fact.
If you're running in the browser, you could also call out to the JS Date.parse(), which does handle that format.

Resources