How to set date format to a range properly? - google-apps-script

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:

Related

Web Intelligence : input control calendar and empty var

I know how to create an empty text var in webi depending input control (using ="" formula). I tried to apply this for dates but I can't select calendar control.
How can I create an empty date var linked to a calendar input control ?
Update :
First I create the date type var
Then I create the input control. I don't have the same interface maybe because of the french version or the support pack difference ?
Finally I update my var
This is certainly not intuitive, but I think this will work for you.
Begin by creating a variable with a value or formula that is a date data type. I called my variable Input Control Date.
=CurrentDate()
This would also work.
=ToDate("06/03/2020"; "MM/dd/yyyy")
We will change this later. The reason for this is so that WebI will give you the option of creating an input control with a calendar date picker.
Create your input control based on Input Control Date.
I think you would want to set the Dependencies to "Whole Document", but you may want to change that based on your specific situation.
Now that you have created your input control with the calendar control to choose the date you can go back and change the value of Input Control Date to an empty string.
=""
If you want to be able to format your chosen date value (or compare it to an object with a date data type) you will need to create another variable and convert it to a date since Input Control Date is not a string and cannot be formatted. That would look like this.
=ToDate([Input Control Date]; "MM/dd/yyyy")
And now a format can be applied.

How to highlight cell if date format is incorrect or blank?

I have an excel sheet with over 5000+ records.
I am trying to set the date column into correct format (dd/mm/yy)
Instead of visually looking at data to spot errors such as:
Blanks
Date inputted like this: 27//01/20 < notice the double //
Or something like this: 27/01/20.. < notice the full stops
Is there an easier way of finding errors in date column?
Here is a sample of my column A:
1st and 4th row should be marked in red, because it is not correct format.
Reason I want to achieve is this is because I am needing to import it into MySQL with correct column types. Not all to be varchar.
Use conditional formatting - choose rule type 'Use formula...', enter formula =NOT(ISNUMBER($A10)) for appropriate range and get red cells.

Issue formatting date values in Google Sheet Query

I created a shared shipment tracker with google sheets where updates are made in a master tab, then filtered into several regional tabs via query function to better visualize shipment status by region. Query used:
=IFERROR(Arrayformula(QUERY(Filter!A2:P&"","select * WHERE Col1 = 'BA'",0)),"No Data Yet")
I made one column (column P) a time stamp column that auto-populates the current date via a simple script every time an update is made in any given cell of the master tab.The script does its job formatting the date as desired, this is the section of the script where I add the date format:
setValue(new Date()).setNumberFormat("mm/dd/yyyy hh:mm:ss");
The problem is that when this data is pulled into any regional tab by the query function, the date format turns into a serial number. I've tried messing with the column formatting in all tabs, however the only way the regional tabs will show the date in my desired format (mm/dd/yyyy hh:mm:ss) is when I manually format the date values in the master tab as 'Plain Text'. Is there a way around this to display the desired date format in both the master and regional tabs without having to continually format the timestamp column in the master tab as plain text every time an update is made?
I'm not sure but how about this:
setValue(Utilities.formatDate(new Date(),Session.getScriptTimeZone(),"MM/dd/yyyy HH:mm:ss");
Just use a string.

"MMMM yy"-date in google spreadsheet

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.

excel format date for mysql

My excel sheet has the following format : dd/mm/YYYY
ex: 24/10/2010 (european format)
and my mysql needs: YYYY-mm-dd (US format)
How can I format the date in Excel to have this US format ?
I tried with cell format, but I don't have the desired format
Regards
Here's how you can find this Number format in Excel:
Go to Format Cells and then the Number tab.
Select Date
Change the Locale to English (U.K.)
The fifth item on the list (on my U.S. version of Excel) is the format you're looking for.
Hope that helps!
For the hours, minutes and second
go in the custom category and enter this :
yyyy-mm-dd hh:mm:ss
Use the text function -- assuming that the date to be converted was in cell A1, =TEXT(A1,"YYYYMMDD") will get your data into a format that mysql will understand as a date.
There are many solutions, but I reformat the dates for mysql using this formula (assuming your date is in cell E2):
=YEAR(E2)&"-"&RIGHT(TRIM(100+MONTH(E2)),2)&"-"&RIGHT(TRIM(100+DAY(E2)),2)