My cell contains a regex formula to extract a date from a string (result is "mm/yyyy", for example "11/2022").
I define a custom date format (so it looks like "November 2022") but Sheets won't apply it.
What could be the reason and/or what am I doing wrong?
edit: a sample of data. My cell contains the following formula
=TO_DATE(REGEXREPLACE(A2, "([0-9]{4})([0-9]{2})(.*)", "$2/$1"))
note: isdate(mycell) returns TRUE
Use DATEVALUE instead:
=DATEVALUE(REGEXREPLACE(A2, "([0-9]{4})([0-9]{2})(.*)", "$2/$1")
PS: you can also use it in array formula ;)
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 am trying to use this formula in google spreadsheet (B2 is a date, eg. 27.11.2020):
=IF(WEEKNUM(now()) = WEEKNUM(B2),"yes","no")
For some reason this is not possible.
When using only:
=WEEKNUM(now()) = WEEKNUM(B2)
I do get TRUE/FALSE, but I need to be able to convert the TRUE/FALSE to YES/NO.
Why does not this work and are there any alternatives?
Issue:
As you can see in the following screenshot or in the documentation:
WEEKNUM accepts a date object but you are passing a string 27.11.2020.
Solution:
You need to convert 27.11.2020 to an actual date object.
You can do that by using this formula:
=IF(WEEKNUM(now()) = WEEKNUM(date(right(B2,4),mid(B2,4,2),left(B2,2))),"yes","no")
You can use the following
=IF(WEEKNUM(now())
=WEEKNUM(REGEXREPLACE(B1,"\.","/")),"yes","no")
OR
=IF(WEEKNUM(now())
=WEEKNUM(SUBSTITUTE(B1,".","/")),"yes","no")
The above formulas work for both European as well as USA formats.
Functions used:
REGEXREPLACE
SUBSTITUTE
IF
I wish to conditionally format cells within a range based on another range...
Eg: format D7:I7 if a value is found in D19:I19.
I've looked but couldn't find a way...
Tried both HLOOKUP& MATCH:
=HLOOKUP(D7,D$24:I$24,,FALSE)
=MATCH(D$7,D$24:I$24,0)`
I have also tried a simple =D$19:I$19 - this one returns only partial formatting on the ranges selected - E9, G11, H13....
Ideas??
Applies to range: D7:I7
Custom formula is: =countif($D19:$I19,$D$7)>0
Have just noticed isDate does not work in arrayformula.
Case
Want to filter all values if dates:
Used the formula:
=FILTER(data,ISDATE(data))
Expected result:
8/28/2018
Got:
#N/A
Question
Why? Other checks work in filter (isNumber, isText, isErr).
Workarounds?
Please try:
=ARRAYFORMULA(ISDATE_STRICT(A1:A11))
The function is currently not documented.
🧐: ISDATE_STRICT wont let date&time format, dates only
Do not know the reason, still curious.
Workaround: =FILTER(data,IFERROR(DATEVALUE(data))) was found here
Note: Workaround will NOT work for dates formatted as:
dd.mm.yyyy
You may use a duck-typed workaround:
=FILTER(data,REGEXMATCH(MID(data,7,4),"20\d{2}"))
Will check if formatted date has a 20XX year string inside.
Now you can convert any formula to arrayformula:
=BYROW(A2:A12,LAMBDA(r,ISDATE(r)))
A workaround that could work depending on what you're trying to do as far as Arrayformula is concerned
=ARRAYFORUMLA(ISNUMBER(VALUE(data)))
VALUE can turn the time into a number
ISNUMBER checks if it's a number
ISNUMBER works fine within ARRAYFORMULA
I have data :- 31-May-07
Its in a calculated column of the list. The method I used to get it :- =IF(FDate="","",TEXT(FDate,"dd-mmm-yy")) {FDate is a DateTime type of column. The returned value is stored in a "Single Line of Text" column type.}
I am now unable to sort that column as its Text now and sorting is done on basis of strings.
I need to sort this column on basis of Date.
Any help ?
Thanks!!
I'm not familiar with Sharepoint but this looks like a pure Excel question. I presume you don't really want to convert the date into text. Let it be a date and just change the cell format.