I have a datestamp in this format on C6:
21/05/2021 10:41:35 PM
How can I split this into date and time so that I have date in D6 and time in E6?
I want to do this because I have browsing history I want to import to calendar.
I found several answers to this question with various answers but none of them worked for me.
You can use SPLIT(C6, " ") to split contents of the cell.
This splits the time and AM/PM too, but you can join it in another cell using JOIN(" ", E6:F6)
date in Google Sheets is always an integer, and time is a fractional number, so you can divide the date and time very easily
Since your data comes from an imported .csv file, it could be formatted as text.
If that is the case, try the following formula
=SPLIT(REGEXREPLACE(A1,"(.*\/\d+) ","$1#"),"#")
You can then format the results to your liking.
(As always, do adjust ranges and locale as needed)
Here is a simple option that you can use as long as each datestamp is exactly the same:
Use the LEFT() and RIGHT() functions. (These also work in Excel)
For the date, use LEFT(DATESTAMP_CELL,10). This will return the first 10 characters from the cell, which in this case are the date "21/05/2021".
For the time, use RIGHT(DATESTAMP_CELL,11). This will return the last 11 characters from the cell, which in this case are the time "10:41:35 PM".
This should be the result:
Related
I want to do a vlookup/sumif based on dates
How can I do it? I saw from a source I have to first change it into numbers
Somehow I cannot do it with formulas like value/Datevalue, I can only convert it by changing its format.
Spreadsheet image
The vlookup() and sumif() functions work fine with dates and date time values.
With vlookup(), you can get an exact match of a date time value by setting the is_sorted parameter to false. To match the first value that is less than or equal to a date time, make sure that the data range is sorted, and set that parameter to true.
With sumif(), if you need to remove the time component from a date time value to match dates to date times, use datevalue().
See this answer for an explanation of how dates and times work in spreadsheets.
I have a Google Sheets Apps Script that uses this method to store data:
sheet.getRange(rowNumber, colNumber).setValue(theString);
Later, those values are retrieved using:
theRowData = sheet.getRange(r, FIRST_DATA_COLUMN, 1, MAX_COLS).getValues()[0];
This seems to be working fairly well except when theString contains a value that looks like a date (such as "6-Dec-2020". Then, getValues() seems to be retrieving a date value (and then converting it to a very verbose string) rather than the string that was written. In this case, I do not want such evaluation of what the data means. I intend to write these values as constants that don't need nor desire interpretation (such as would be done by apostrophe in Excel with a value like "'6-Dec-2020"). Is there a way to retrieve exactly the same value that was stored (or the store exactly the value that was intended), in exactly the same format?
For this specific problem example, I'm getting back "Sun Dec 06 2020 00:00:00 GMT-0500 (Eastern Standard Time)" when what I wrote (and what I want returned) is "6-Dec-2020" . I do realize I could set number formats, but that won't always work, as these values (that admittedly look like dates) are sometimes in other formats, like "6-Dec" among others, and I would need "6-Dec" back when reading in that case.
Use getDisplayValue() or getDisplayValues().
The displayed value takes into account date, time and currency formatting formatting, including formats applied automatically by the spreadsheet's locale setting
I am using Google Sheets to collect some data I need a cell to only allow a duration hh:mm input.
Here is the formula data validation I have right now
=regexmatch(text(E11,"hh:mm"), "[0-1][0-9]:[0-5][0-9]$")
The only thing this is not doing for me is not allowing whole number responses (i.e. 1,3,5..). These values break some formulas that I have as 7 = 168 hours in duration. What can I do to limit only to hh:mm format entry?
I am willing to use a script if this is what is needed.
=REGEXMATCH(TO_TEXT(E11),"\d{1,2}:[0-5]\d?")
TO_TEXT gets display values instead of number.
\d{1,2} adds a condition for a 1 to 2 digit number.
I have a date column. I want to highlight each date that is 90 days old or older in Column "C". For single cells it's easy using Date is before, exact date, and then:
=TODAY()-90
but for the entire column I struggle to find how to insert the function so it keeps working for all cells. I tried something like Date is before, exact date, and:
=ARRAYFORMULA(TODAY()-90>C2:C200))
Sadly, this does not work. Any suggestions?
Please try:
=and(today()-C1>90,C1<>"")
as "Custom formula is" with formatting of your choice and Range: C:C (or to suit).
The 'engine' is today()-C1>90 but this is wrapped above in an and so blank cells are not also formatted by the rule.
Applies to New Google Sheets.
I have a google spreadsheet in which I want a date with only the name of the month and the year, like September 2011, and I also want the month and year to be easily changeable.
Is there any way of getting custom date formats to do this?
I figured out I could do like this:
=TEXT(40295; "MMMM yy")
But then the datepicker can't be used anymore and changing the date is made impossibly hard..
Is there any good way of solving this?
You can set a custom format to a cell using Google Apps Script.
Open the script editor (menu Tools > Script editor), paste this, save and Run > onOpen.
function onOpen() {
SpreadsheetApp.getActive().addMenu(
'Format', [{name:'Custom', functionName:'customFormat'}]);
}
function customFormat() {
var format = Browser.inputBox('Write the format to be applied on the seleted cells');
if( format !== 'cancel' )
SpreadsheetApp.getActiveRange().setNumberFormat(format);
}
On your spreadsheet a new menu should appear in the end where you can pick the Custom entry to enter your custom format for the selected cells.
Google Spreadsheet does not yet permit you to apply a custom number format to a cell.
You can of course enter the date into a cell, and then reference that date in a second cell:
A1:4/27/2010, A2=TEXT(A1;"MMMM yy")
This would meet your requirements: it would display the date the way you wanted, and allow the date to be easily changeable.
But it has the undesirable side effect of having the date appearing twice on the sheet. I often work around side effects like this by printing or exporting a range instead of the entire sheet. So maybe there is also a practical workaround in your case.
I thought yy just gives the 2 digit year.
I used the following:
=text(E2,"MMMM YYYY")
E2 was the specific cell I used, but you could use any cell.
You can enter any format (for dates or others) as a Custom Number Format.
Highlight the cell range and Go to Format > Number > More Formats > Custom Number Format. Then enter
mmmm" "yyyy
gives "September 2011"
or any other format
ddd" "mm"/"dd"/"yyyy
would give "Mon 09/11/2011"
note the missing quote at the beginning and the end.
it shows how it will display as you experiment.
Quotes in the beginning or end give you invalid format
Saves you having two fields (the data, and the text() formatted one)
Its not intuitive (either the format, or where to put it). But works better than importing an xls.
I accidentally found a workaround for a custom date format. I had a custom date format using Excel. When uploading the Excel file, the date format (mm/dd/yyyy hh:mm am/pm) stayed in that format even though that was not a supported Google Sheet format. Then using the format painter, I was able to copy that format to other cells within Google Sheet. I know this is not an ideal solution, but seems to work. I have not played with how many other custom formats I could create in Excel, convert to Google Sheet and then use format painter to use with other cells.