In this tutorial, I will show you the differences between getValue and getDisplayValue in Google Apps Script.
I used a default project with a default spreadsheet document with my birthday 1976-03-07 into A1 cell and format text as year-month-day.
I add Apps Script API to my project.
On the spreadsheet, I used Tools – Script editor to create my Google apps script.
I get my project id and set it on my default script on the Resources – Cloud Platform project…
Let’s see the Google Apps script I used:
1 2 3 4 5 6 7 8 9 10 11 | function test_getValue() { var ss = SpreadsheetApp.getActiveSpreadsheet(); //var sh = ss.getSheetId()[0]; var sh = ss.getSheetByName("Sheet1"); var val = sh.getRange("A1"); var test_getValue = val.getValue(); var test_getDisplayValue = val.getDisplayValue(); var ui = SpreadsheetApp.getUi(); ui.alert('getValue = '+test_getValue+'| getDisplayValue = '+ test_getDisplayValue); } |
The run of this script will show a message alert into a Spreadsheet with this text:
1 | getValue = Sun Mar 07 1976 00:00:00 GMT+0200 (Eastern European Standard Time)| getDisplayValue = 1976-03-07 |
You can clearly see the differences between the two functions.