Google Sheet wrong date and time format for Timeline Graph - google-sheets

I import Tasker data source into a Google Sheet, but Timeline Graph does not work.
The format of the Date and Time is not understood.
The format of my data source is dd-MM-YYYY HH.mm
For example:
16-10-2020 00.40
But Google Sheet understands only dd/MM/YYYY HH:mm:ss
16/10/2020 00:35:00
See here
(On the second picture, I modified the date to be 16/10/2020 00:35:00, and applied Date and Time format, so it display 16-10-2020 00.35, which serves no purpose other than confusing you)
I've tried to change the format of the date, but the only thing it does is:
Convert an already existing 16/10/2020 00:35:00 format
To 16-10-2020 00.40
I want the opposite.
I'm tired and kind of angry at Google Devs. I'm been searching for hours, and I find it crazy Google Sheet cannot understand this simple format.
Please any idea?
Thank you

Please use the following formula to convert your values to dates
=ARRAYFORMULA(IF(A2:A5="",,--REGEXREPLACE(REGEXREPLACE(A2:A5,"-","/"),".",":")))
Depending on your locale you may have to change , to ;
=ARRAYFORMULA(IF(A2:A5="";;--REGEXREPLACE(REGEXREPLACE(A2:A5;"-";"/");"\.";":")))
Functions used:
ArrayFormula
REGEXREPLACE

An alternative to the solution already provided
Google Sheets Formulae
You can use this formula in order to replace the . with : and drag it down in order for it to be applied to all the cells:
=REPLACE(A1,14,1,":")
This will result in a column with the date formatted in the way you want it.
Google Apps Script
You can also make use of Apps Script in order to replace all the . with : directly in the sheet.
// Copyright 2020 Google LLC.
// SPDX-License-Identifier: Apache-2.0
function toDate() {
var ss = SpreadsheetApp.openById("SS_ID").getSheetByName("SHEET_NAME");
var range = ss.getRange(1,1,NO_OF_ROWS,1);
var values = range.getValues();
for (let i=1; i<values.length; i++)
ss.getRange(i, 1).setValue(new Date(values[i-1][0].toString().replace(/\./g, ":")));
}
The script above also sets the value to be of type date.
Reference
REPLACE formula Google Sheets;
Google Apps Script.

Related

How can i change "-infinity" to today's date in Google Data Studio or Google Sheets?

I've got a text field containing different dates and cells containing -infinity (meaning today's date).
How can I change -infinity to today's date in Google Data Studio or Google Sheets and how do I change the cell from text to date?
The image below contains the column with the dates and -infinity.
Apart from the formula already presented in the previous answer, you can also make use of Apps Script in order to achieve your task.
Apps Script version
You will have to go to Tools > Script editor and use the code below which loops through the A column and whenever it encounters an -infinity value, it replaces it with the current date.
function replaceInfinity() {
let ss = SpreadsheetApp.getActiveSheet();
let validUntil = ss.getRange("A2:A").getValues();
for (let i=0; i<validUntil.length; i++)
if (validUntil[i][0] == "-infinity")
ss.getRange(i+2,1).setValue(new Date());
}
Before
After
Reference
Google Apps Script.
Now that you have added a spreadsheet, I duplicated your raw data sheet and added a processing formula in B1:
=ArrayFormula({"valid_until V2";IF(A2:A="";;IFERROR(VALUE(REGEXEXTRACT(A2:A;"\S+"))+VALUE(REGEXEXTRACT(A2:A;"\s([^/./+]+)"));DATEVALUE("1/1/2050")))})
This one array formula produces all results for Column B, including the header (which you can change to whatever you like).
I processed your "infinity" dates to show as the real date January 1, 2050 — a date far enough in the future to essentially serve the same purpose as "no expiration."

Why does a different result show up when filtering a date in google sheets?

I'm very new to programming so I'm not sure how to phrase this but in google sheets, I'm having a problem:
when filtering results using =IFERROR(FILTER('Segment Management'!B:B,'Segment Management'!A:A=B5)), it works perfectly fine with letters and numbers but when there's a date in Segment Management cell B5 it instead of saying the date (in this case 15/3/2020) it outputs "43906". Could I get some help to explain why it says this number instead of the date?
Date is considered as plain number in google sheets that's the reason you get numbers instead of date you can either do either of one
Select the column where you have put formula & in menu Format> Number> and select date formatting
OR
use this formula =ARRAYFORMULA(TEXT(FILTER('Segment Management'!B:B,'Segment Management'!A:A=B5),"DD/MM/YYYY"))

How to change MM/DD/YYYY to DD/MM/YYYY

I have imported a CSV file to the spreadsheet that includes columns with Dates and timestamp (Columns D,E,K,L) and I'm currently facing 2 problems with these columns.
Some rows are formatted as text/string and I can't seem to change it to date format. I tried manually changing it via format>number>datetime but it remains the same.
the format of the date is being read incorrectly by spreadsheet. For example, 5/11/2018 is being read as May 11, 2019 but if you try to review the spreadsheet, it should be read as November 5, 2018. I tried playing with the format and spreadsheet settings to no avail.
Spreadsheet Sample
I'd appreciate any inputs.
UPDATE
For Column D & E, I have already converted all rows to Date but the problem persists where in some rows are being read as DD/MM/YYYY and some rows MM/DD/YYYY. This creates date discrepancy when I try to make data visualization using these data:(
I am unable to convert all rows in Column L to date format. Some rows are still being read as text/string.
if you have a spare column you can use this formula to correct it:
=DATE(RIGHT(A1; 4); MID(A1; 4; 2); LEFT(A1; 2))
also, you can try to change locale settings in your spreadsheet because it looks like that your spreadsheet uses mm/dd/yyyy format as default. eg. you can try for example Czech locale where default is dd/mm/yyyy
To format custom dates in Google Sheets:
Highlight the column to be formatted.
Navigate the app's menu path:
Format >> Number >> More Formats >> More data and time formats
Put your cursor in the top field of the popup and edit as necessary...
Delete parts you don't want.
Add parts you do want (but make sure you're adding them left-to-right).
Put character(s) between the fields as separators.
Format each part via its dropdown list of options.
Click the "Apply" button, and you're done.

Display text representation of a date as a formula result

I get this date format from Zapier
2018-08-16T01:13:58
I use this formula to split and extract the first half of the split (the date).
=index(SPLIT("2018-08-16T01:13:58","T"),0,1)
Google Sheets displays the formula output as a number, e.g. 43328
If I format this cell manually, using the menu Format >> Number >> Date, Google Sheets will display it as the formatted date, e.g. 16/08/2018
If I use DATEVALUE() as such:
=datevalue(index(SPLIT("2018-08-16T01:13:58","T"),0,1))
then the cell displays #VALUE!
Error DATEVALUE parameter '43328' cannot be parsed to date/time.
How can I write my formula such that it is displayed as formatted date, without having to format the formula's cell through the menu?
You can use the TEXT function:
=TEXT(43328,"dd-mm-yyyy")
Date shows in google spreadsheet are formatted by google spreadsheet settings. If you want to change the datetime format of your sheet, you will have to change Locale setting to that of your need.
If you don't want to go over settings, you can set it manually by code.
First, you will need to put this formula =SPLIT("2018-08-16T01:13:58","T") + "" somewhere to get the date value. Here I assume you use cell "Z1"
Now, you will have to change the date format each time "Z1" changes it value. I use onEdit(e)
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSheet()
if (range.getColumn() == 26 && range.getRow() == 1) { // if Z1 is modified
var d = ss.getRange("Z1").getValue()
var inputDate = Utilities.formatDate(d, "GMT+7", "dd/MM/yyyy")
ss.getRange("B5").setValue(inputDate)
}
}
There you go. Each time Z1 change, which means the date value is inputted, the correct date + format will be reflected in B5.
After much searching this seems to work for me.
=regexreplace(SUBSTITUTE(SPLIT("2018-08-16T10:02:29","T") + "","-","/"), "^(\d+).(\d+).(\d+)$", "$3/$2/$1") & " " & regexreplace(RIGHT("2018-08-16T10:02:29", find("T","2018-08-16T10:02:29") -3), "^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$", "$1:$2:$3")
Outputs 16/08/2018 10:02:29

Exclude dates from a range in google spreadsheets

I am new to google spreadsheets & trying to exclude dates from a range in google spreadsheet in following way.
I have following cells in range (c2:c7):
4/9/2015 9:21:09
4/9/2015 17:50:24
4/10/2015 17:25:57
4/11/2015 17:07:00
4/13/2015 18:13:35
4/14/2015 17:00:58
I want to exclude all dates and want following range in B2:
9:21:09
17:50:24
17:25:57
17:07:00
18:13:35
17:00:58
I have tried using regexextract function but could not succeed, can anybody help please, I have mentioned this in following link:
https://docs.google.com/spreadsheets/d/1tsmeLz_TZ_nm_1M40bzM7cKq9mU_FUeFxdsk0fnL6wo/edit#gid=0
try:
=ArrayFormula(mod(C2:C7,1))
where C2:C7 is the range with the timestamp. Format the column with the output as TIME (via the 123-button)
Use a regex.
/(two numbers):(two numbers):(two numbers)/
After pulling each of these parts from the dates, save them into an array and set them in column B. (It's preferred to copy to a 2D Array then use Range.setValues() for speed).
This works:
=TEXT(A1,"HH:MM:SS")

Resources