I'm trying to enter dates without slashes, for example 09092013.
Is there a quick and easy way to convert those strings into date objects?
ParseDateTime() didn't like it.
You mean other than using left() to get the first two, mid() the second two, and right() the last four, then using those as inputs into createDate()? how much quicker and easier are you wanting to get?
You could use Java
formatter = CreateObject("java", "java.text.SimpleDateFormat").init('MMDDYYYY)';
formattedDate = formatter.parse(yourDate);
Related
I'm trying to keep lines that contain the word "NOA" in a column A which has many multi-line cells as can be viewed in this Google Spreadsheet.
If "NOA" is present then, I would like to keep the line. The input and output should look like the image which I have "working" with too-many helper cells. Can this be combined into a single formula?
Theoretical Approaches:
I have been thinking about three approaches to solve this:
ARRAYFORMULA(REGEXREPLACE - couldn't get it to work
JOIN(FILTER(REGEXMATCH(TRANSPOSE - showing promise as it works in multiple steps
Using the QUERY Function - unfamiliar w/ function but wondering if this function has a fast solution
Practical attempts:
FIRST APPROACH: first I attempted using REGEXEXTRACT to extract out everything that did not have NOA in it, the Regex worked in demo but didn't work properly in sheets. I thought this might be a concise way to get the value, perhaps if my REGEX skill was better?
ARRAYFORMULA(REGEXREPLACE(A1:A7, "^(?:[^N\n]|N(?:[^O\n]|O(?:[^A\n]|$)|$)|$)+",""))
I think the Regex because overly complex, didn't work in Google or perhaps the formula could be improved, but because Google RE2 has limitations it makes it harder to do certain things.
SECOND APPROACH:
Then I came up with an alternate approach which seems to work 2 stages (with multiple helper cells) but I would like to do this with one equation.
=TRANSPOSE(split(A2,CHAR(10)))
=TEXTJOIN(CHAR(10),1,FILTER(C2:C7,REGEXMATCH(C2:C7,"NOA")))
Questions:
Can these formulas be combined and applied to the entire Column using an Index or Array?
Or perhaps, the REGEX in my first approach can be modified?
Is there a faster solution using Query?
The shared Google spreadhseet is here.
Thank you in advance for your help.
Here's one way you can do that:
=index(substitute(substitute(transpose(trim(
query(substitute(transpose(if(regexmatch(split(
filter(A2:A,A2:A<>""),char(10)),"NOA"),split(
filter(A2:A,A2:A<>""),char(10)),))," ","❄️")
,,9^9)))," ",char(10)),"❄️"," "))
First, we split the data by the newline (char 10), then we filter out the lines that don't contain NOA and finally we use a "query smush" to join everything back together.
I'm importing some stuff from a google form into a google sheet. I want to delete the 'time' part of the timestamp, and copy it to another spreadsheet. I'm trying to use REGEXREPLACE to do this, but REGEXREPLACE is throwing a Formula parse error. It seems like REGEX is a different programming language altogether, so am I not using REGEXREPLACE correctly? Or am I not putting the arguments in correctly? (Btw, I'm using the more general expression so that I can use it for any "entries")
Here's the actual doc:
https://docs.google.com/spreadsheets/d/1YcHk5ylw3w7-V2AusaY2ktsyDEbtKzlIkFdS9quM8rE/edit?usp=sharing
Just replace single quotes ('') with double quotes ("").
To extract the date, you can use the INT-function
= INT(A2)
Then, formatted as Date, the time component is gone.
This works because the value of 1 represents 1 day of a DateTime. Time is a fraction of a day, for example, 0.33333 is 8 hours (1/3 of a day). The INT-function removes the decimal part and therefore only the date without time remains.
I have a string say: '212'. This string is dynamically generated.
Is there a way to add these numbers together without looping?
If needed, I will loop and add the values; but after researching the Adobe Docs I wanted to see if there was a better way.
Thank you
Sure.. just for fun.
digits = 212;
sum = arraySum(listToArray(digits, ""));
writeOutput(sum);
Run script above: http://trycf.com/gist/3677b4e7d17d4fbac37d/acf
Fairly new to classic ASP(maintaining legacy applications) and I need to figure out how to fish out values from a string. String itself can look something like this - 0,12,234,543. I was thinking about making a function where I can specify which number I want from the string for ex.
Function fnGetNumber(string, 3)
// returns the third number(number after the second comma ie. 234)
End Function
The string will always have only numbers and always 4 of them. Also they will not have decimal places.
The function itself is not a problem, but I can't figure out the regex.
Using Split is the way, use it to transform the string to an array and pull the data from that.
I wouldn't recommend regex as whilst it powerful, its readability is poor.
I have a string in date format 06/09/2011 03:00 PM. I want to remove all of the forward slashes, and if the first digit of the month (06) is a zero, remove it as well as the first digit of the day (09) remove it as well. Any body who can help me out?
thanks!
The usual way to do this is by taking an available date parser where you hand in the input format and output it to a different output format.
Patterns differ, Implementations etc differ also. It is not convenient neither practicable to do date parsing via regex.
Something like that
0([1-9]+)/0([1-9]+)/([0-9]+)
Of course, it will only work in valid dates; it does not parse the date or anything.
BTW: I find better (more readable, detects errors in a more meaningful manner) fyr's answer. This is just to show that it can be done with regex, if fyr's solution is not available in your platform.