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
Related
I have a column of cells containing dates, all in the format "YYYY-MM-DD HH.mm", I would like to convert them to a format that is then sortable by the SORT() function of GSheets, using a formula and not scripts. I tried DATE but I can only convert the date without the time. Is this possible to do?
You can use the following formula:
=date(left(A1,4),mid(A1,6,2),mid(A1,9,2))+time(mid(A1,12,2),mid(A1,15,2),0)
You can use DATEVALUE and TIMEVALUE too: the sum will return the result.
=DATEVALUE(A1)+TIMEVALUE(A1)
Then, format the cell accordingly so it displays the date instead of the number
I'm trying to concatenate a column of dates and other of hours.
The fuction:
=CONCATENATE(TEXT(AGENDA!B9 ,"dd-mm-yyyy"), " ", TEXT(AGENDA!C9 ,"hh:mm:ss"))
works, but, some cells are in fuction format, dd-mm-yyyy, and some others are dd/mm/yyyy (the time is correct). I need them all with -
You have a non valid date in AGENDA sheet Fecha column note Luque, Hugo 20/08/2021 with month set to 20 !! and day is 08.
To add date validation, Select B2:B and go to Data data > validation > Criteria: date.
and select On invalid data: Show warning.
Fix the date one by one or take a look at the quick fix.
To check the date format:
Go to Formst > number > Custom date and time.
The Quick fix
To get date fixed with a formula from, mm/dd/yyyy to dd-mm-yyyy you need a helper column lets call it Fixed Date, with the formula.
=IF(ISDATE(B2)=False,CONCATENATE(INDEX(SPLIT(B2,"/-"),1,2),"-",INDEX(SPLIT(B2,"/-"),1,1),"-",INDEX(SPLIT(B2,"/-"),1,3)),B2)
Explanation
1 - IF(ISDATE(B2)=False check the date is valid if true return the original value example B2 if false calculate the formula.
2 - INDEX(SPLIT(B2,"/-"),1,2) to get the month column that resulted from SPLIT function with column set to 2.
3 - INDEX(SPLIT(B2,"/-"),1,1) to get the day column that resulted from SPLIT function with column set to 1.
4 - INDEX(SPLIT(B2,"/-"),1,3)) to get the yaer column that resulted from SPLIT function with column set to 3.
5 - CONCATENATE the columns with "-" in between.
Now you can paste your formula but adjusted in BBDD.AGENDA Sheet B3 cell.
=TEXTJOIN(" ",TRUE,TEXT(AGENDA!C2 ,"dd-mm-yyyy"),TEXT(AGENDA!D2 ,"hh:mm:ss"))
Notice that we changed AGENDA!B2 with AGENDA!C2.
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."
In column A I have date and time.
In Column B I have this formula to split them:
={"COL B","COL C"; ArrayFormula(IF(NOT(ISBLANK(A2:A)), SPLIT(A2:A, " ")))}
My sheet is linked to a Google form.
Every time a new sheet is submitted, the new data looks like 44075 and 0.9756944444 and I always need to format as Date and the other one as time.
Is there any way that my formula will automatically format the splitted value in col b and c?
You might try this:
={"Date","Time"; ArrayFormula(IF(ISBLANK(A2:A),, {DATEVALUE(A2:A),TIMEVALUE(A2:A)}))}
or this:
={"Date","Time"; ArrayFormula(IF(ISBLANK(A2:A),, {INT(A2:A),MOD(A2:A,1)}))}
In either case, you'll want to do Format>Number Date for B and Format>Number>Time for C.
UPDATE:
Since you seem to want the formatting to appear a certain way without using the Format>Number option, this will output dates and times...
=ARRAYFORMULA({"Date","Time";IF(A2:A="",,TEXT(A2:A,{"m/d/yy","h:mm am/pm"}))})
I've tried a lot of formula and surrendered.
I've just added a script:
var date = ss.getRange('R2:R');
date.setNumberFormat("MM/dd/yyyy");
var Time = ss.getRange('S2:S');
Time.setNumberFormat("hh:mm:ss AM/PM");
I have a column that store the date and I try to implement a conditional formatting custom formula that switch background color of an entire row (or multiple cells of a row) if the day is odd or even.
Here is a coma separated value version of my sheet and what I try to achieve. Date and time are in separate columns. I can have multiple rows with the same date (different times). Rows with the same date must have the same color.
Date, Time, Data
01/12/2014, 01:00, "xxxx" -> BG = X
01/12/2014, 03:00, "xxxx" -> BG = X
02/12/2014, 01:00, "xxxx" -> BG = Y
03/12/2014, 01:00, "xxxx" -> BG = X
03/12/2014, 02:00, "xxxx" -> BG = X
04/12/2014, 03:00, "xxxx" -> BG = Y
To compute if the day is even or odd, I wrote a simple function that return the number of days since 01/01/1970:
/**
* Return the day of the year of a date or a range
*
* #param {date}|{Array.Array} Date or range.
* #return The day of year.
* #customfunction
*/
function DAYSFROM70(date)
{
if (date.map) {
return date.map(DAYSFROM70);
} else {
if (!date instanceof Date || !date.getTime) {
return "";
} else {
return Math.ceil(date.getTime() / 86400000);
}
}
}
And this is the custom formula I tried to apply (note that DAYSFROm70 function is using a range as parameter), without success:
=ISODD(DAYSFROM70($B$2:$B$101))
The following formula does color cells backgrounds (but I obviously can't use that, sunday and monday are both odd):
=ISODD(WEEKDAY($B$2:$B$101))
Something is wrong with my script but I can't figure out what...
Check out this spreadsheet for testing:
https://docs.google.com/spreadsheets/d/1U49FoeMPKlvjCURsqS7GxTH62u_fTJNCcH12XFQtWVQ
Thanks for your help.
why cant you just do: =isodd(day(A1)) ??
select whole sheet
click format -> conditional formatting
from the dropdown choose "custom formula"
in the formula box put: =isodd(day($A1))
select your format (background color)
click ok.
edit
in your question you did not speciffy what you meant by "day is odd".
since you want to colour rows for "every other day" irrespective of day of year, month, or year you can just do (using build in functions):
=isodd(DATEVALUE($A1))
[please read instructions above on applying the conditional formula. You DO NOT need to use a range or array]
DO NOT REFER TO A RANGE IN THE CONDITIONAL FORMATTING FORMULA!! "=ISEVEN(WEEKDAY($B$2:$B$23))" <- NO!!
"=isodd(DATEVALUE($A2))" <- YES!! (where A2 is the topmost row of the range you are formatting - as written in the "range" box in the conditional formatting popup dialog)
It seems Google Spreadsheet doesn't support dates in that format. Using your function, I get an error when trying that format, but if I remove the times from the end, it works fine.
Work around: Add the date as a custom format: https://support.google.com/docs/answer/56470?hl=en
I got it work with: "12/1/2014 1:00:00" by setting the format:
Year(1930)-Month(08)-Day(05),Hour(1):Minute(1)
----EDIT-----
I set the conditional formatting to:
=ISODD(DAYSFROM70($A1))
I had the dates in column A, so this will change the entire row is the date is odd.
Hope this helps
If your dates are in ColumnA please try Format, Conditional formatting..., Custom formula is :
=isodd(text($A1,"#"))
with formatting of choice applied to Range: A:Z (or extended as required).