"MMMM yy"-date in google spreadsheet - google-apps-script

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.

Related

How to write text data unevaluated to google sheets cell

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

How to set date format to a range properly?

When I set a Date format to cells, it doesn't change format to dates, it is still Plain text format.
When it is a date format you can see the calendar in a cell when double-clicking (like on the picture that I attached at the bottom).
How to set the date format to a range properly?
p.s. see another screenshot below with data validation from a named range.
//dates range
var weekEndingsRange = ss.getRangeByName("StatisticsWeeks")
weekEndingsRange.setNumberFormat('mmm dd, yyy')
(did you try the proper way?) set up Data Validation for valid date:
and then use the internal/native formatting of Google Sheets:

How do you move a just the date with spaces, time and AM/PM in Excel/CSV with a formula?

I have a date in an excel/csv document that was exported from an old ASP app that I am going to import into Wordpress/MySQL and I just need to display the date. Each cell has a date like this:
2/22/2006 6:27:55 AM
I just want
2/22/2006
I am moving the date from 1 sheet to another by looking up an ID number and all the other data I was able to move with formulas no problem (=VLOOKUP(G2,Firm!$A$2:$P$1392,4,0)
when I move the date it turns it into 38770.76938
I was going to try to remove the ( 6:27:55 AM) but this formula wasn't working either: =LEFT(P2,FIND(" ",P2&" ")-1)
Can anyone help? There are about 5,000 entries.
#greg-you can format column using custom modification.
Please check this link contains details:
https://support.office.com/en-us/article/Format-a-date-the-way-you-want-8e10019e-d5d8-47a1-ba95-db95123d273e
Use this formula
=MONTH(A2) & "/" & DAY(A2) & "/" & YEAR(A2)

General cell in excel to ms access date

I have this column in excel in general cell format that contains the date in the following format. eg "18-05-2013" which is "DD-MM-YYYY".
In access, it somehow comes out automatically in this format "##/##/****".
Where ## and ## they sometime treat it as day, sometimes treat it as the month.
Somehow it is messed up. What is the way to format given my situation?
The format I want it to be is "DD/MM/YYYY" in access
A quick use of the replace function solved it!
Hiring Date: Replace([Hire Date],"-","/")

ms access data type issue when using a linked table to an excel document

I have a spreadsheet which is a report from an external supplier. The date columns are formatted completely different from how a little acccess database works, so i decided to record a macro in excel to alter the 3 columns to a dd/mm/yyyy format (im uk btw). This all works great and the column isshowing as above and is listed as a 'DATE' format also.
Now i use access to link to this excel sheet by means of a linked table, but i noticed that any queries that i wish to filter on those fields in the form of a where clause, it does not pull in the expected result IE it pulls all dates and not the ones between what i asked for in the queryalmost as if it is not recognizing them as dates see the where clause below
WHERE LatestGamma.ConfirmedPortingDate Between [Please Provide 1st Date (dd/mm/yyyy)] And [Please Provide 2nd Date (dd/mm/yyyy)];
I also tested it by using actual dates in the between cluase and it still appears to ignore it.
When i look at the properties of linked table for those columns, it shows that the fields are: dd/mm/yyyy;# but are showing as text??
When i look at the excel macro to see what code the macro used for changing the date format of the columns i see:
Columns("F:H").Select
Selection.NumberFormat = "dd/mm/yyyy;#"
I have another excel sheet that is used as a linked table and date columns are working fine and show as date/time and not Text. Its almost as if excel is putting some meta data into the columns that is making access interprate them as text (even though they are formatted as date)
Im stuck her some help/advise would be great
Its hard to tell without looking at the file, but it seems the main culprit is the excel macro which is not converting the string to date format correctly. You can try converting string into date format by using something like this in excel VBA
Sub convert()
Dim str1 As String
str1 = Range("f6").Value
startdate = CDate(str1)
End Sub
You probably will have to loop thru all the cells to convert the string (text) into date format.
Sorted it in the end. It was more or less what i was thinking IE the column although was showing as a Date type seemed to be storing it as some sort of text. Anyway the way round it was to use the text to columns button and force it to be a date in DMY format.
Once i had tried it i then recorded the actions as a macro and copied the resulting code to my main macro at the end, bingo ! Access now sees it as a date and not text.
Not sure if it is a bug or not but Excel can be a real pain sometimes especially with phone numbers, having to store them as a data type text to keep the leading zero and then immediately converting them to General to allow vlookups etc. I guess that is the same sort of thinkg going on above showing as a date yet actually having like a suedo text meta thing going on...