I am struggling to convert a bunch of dates in Google Sheets.
My dates are in the format mentioned in this image.
Some dates have AM/PM in them, while some have a / instead of a -.
I need to convert them to yyyy"-"mm"-"dd" "hh":"mm":"ss while converting the time to 24hour format in case of PM.
Does anyone know a way to achieve this?
The problem is that most of your data uses the American date convention m/d/yyyy while your spreadsheet uses the Indian d/m/yyyy date convention. But then again, some of the data appears to already be in the ISO8601 format you are requesting as the result format. To convert all the dates, use this:
=arrayformula(
if(
isnumber(A2:A) + isblank(A2:A),
A2:A,
regexreplace(A2:A, "^(\d+)/(\d+)/(\d+)(.+)", "$3-$1-$2$4") + 0
)
)
Format the result cells as Format > Number > Date time or as the custom format you mentioned. See the new Solution column in your sample spreadsheet.
Suppose your raw data is in A2:A. Clear B2:B and place the following into B2:
=ArrayFormula(IF(A2:A="",,IFERROR(DATEVALUE(A2:A&"")+TIMEVALUE(A2:A&""),DATEVALUE(A2:A)+TIMEVALUE(A2:A))))
This formula has error control built in, to handle the raw data if there is a mix of strings and real date-times.
Next, select the entire Column B. Apply Format > Number > More Formats > Custom number format and enter the following in the text field at the top: yyyy-mm-dd hh:mm:ss
Related
I have a column, in which datetime in text format "2022-04-12 07:09:10 UTC". I want to change this into IST time zone and convert it into date format only
You'll need to extract the date and time then add on 5h30m. From there you can either wrap it with INT or format the column to show just the date. For the one below, I used INT, which will strip the time after it is converted.
=ARRAYFORMULA(
IF(ISBLANK(A2:A),,
REGEXREPLACE(A2:A,"UTC","")+
TIME(5,30,0)))
Unfortunately, the Google-Sheets sync extension saves the timestamp as a string. (Example: February 6, 2022 at 11:40 pm). Is there any way of automatically converting this automatically to an actual date? I tried the usual date conversion formulas but they dont work. Maybe a work-around?
if a timestamp is in cell A2, try this:
=1*SUBSTITUTE(A2,"at","")
This just gets rid of the word "at" and then multiplying by 1 forces an attempt to convert it into a date value. Then you can just do a regular Format>Number>Date and Time on that cell and it should show how you'd want.
Suppose that your string-dates are in A2:A.
Place the following formula into the Row-2 cell of any other open column (e.g., B2):
=IF(A2:A="",,DATEVALUE(REGEXEXTRACT(A2:A,"^(.+),\s"))+REGEXEXTRACT(A2:A,"\d+:.+$"))
Row 1: cell A is a concat of the date in B and the time in C. I generate these with CTRL+: and CTRL+SHIFT+: respectively. Google sheets does not treat this like a timestamp on the x axis of charts
Row 2: I discovered CTRL+ALT+SHIFT+: to do a full timestamp, now it has a real timestamp
The issue is, I have many rows of recorded data of the type in Row 1 -- is there any way to convert this into a 'time' format that Google Sheets will respect on the x-axis of charts? Using VALUE() just gives the date portion of the timestamp.
Kind of crazy how much trouble this is causing me, is there really no date_parse(string_format) type function I can call?
EDIT:
this is ridiculous, just going to export and use python
instead VALUE use TIMEVALUE and then format it internally to time
or:
=TEXT(TIMEVALUE(A1); "hh:mm:ss")
for arrayformula:
=ARRAYFORMULA(IF(A1:A="",,TEXT(TIMEVALUE(A1:A); "hh:mm:ss")))
for timestamp > date use DATEVALUE
I am using the Twilio log file to crunch some data and need to convert the Twilio format for dates into something that Google Sheets can recognize as a date so I can then extract what month the date is referring to. I think that first, the text string has to be converted to be a better format and then I can use one of Google Sheets functions to extra the month. Currently, this is the format in the log file:
"2019-08-22 06:12:58 MDT"
I used GoogleSheets TIMEVALUE and TEXT functions.
=TIMEVALUE(I2)
and
=text(I2,”mmmm”)
I get "Formula Parse Error"
The timezone stamp is messing up the Google formulas for you.
So you may want to try getting rid of that with something like this:
=text(index(split(I2," "),,1),"mmmm")
The split function breaks up the logged time stamp into 2019-08-22 | 06:12:58 | MDT across three columns.
And the index function then gets the just the first column - the date bit from there.
And then the text function gets the month name out of the date.
you can use:
=TEXT(LEFT(A1, 10), "mmmm")
and in array it would be:
=ARRAYFORMULA(TEXT(LEFT(A1:A, 10), "mmmm"))
I am trying to use blew expression in Google SpreadSheet.
=min(GoogleFinance("HKDUSD","price",date(A2)-1,date(A2)))
But since A2 data is in mm/dd/year format, we need to convert it to yy,mm,dd format as parameter of date().Does Google SpeadSheet has some API to do such convert?
It actually works if you just add the dates as they are without the date function wrapped around them
=min(GoogleFinance("HKDUSD","price",L1-1,L1))
Edited: To answer your follow up question about the date format - a formulaic workaround you do uses regex replace and basically just swaps the two capture groups in month and day with this regex "(\w+)/(\w+)":
=min(GoogleFinance("HKDUSD","price",REGEXREPLACE(L1,"(\w+)/(\w+)","$2/$1")-1,REGEXREPLACE(L1,"(\w+)/(\w+)","$2/$1")))