0

I got 5 digit Julian date (I hope it is Julian date, I just got this data and need to work with it) in a Google Sheet (26933) that I can convert to human readable form by clicking Format - Date. So it becomes 26.09.1973.

I found that I can do the same using Google Application Script when I use this code cells.setNumberFormat("d.M.yyyy");

but it changes the format of the sheet. How can I achieve the same only in memory not changing the sheet at all?

Marios
  • 26,333
  • 8
  • 32
  • 52
Radek
  • 13,813
  • 52
  • 161
  • 255
  • 1
    can you elaborate more on that: `achieve the same only in memory` . You mean you want to use the date in a script (but not change the sheet at all) ? – Marios Apr 14 '21 at 15:15
  • yes, exactly. You are right @soMario – Radek Apr 14 '21 at 17:44

1 Answers1

2

if you want to convert a julian date to a regular date using javascript then here is the thread you should be focusing on:

Convert a Julian Date to regular date in Javascript

However, if you are looking for a Google Apps Script trick, then you can change the format, get the date and then change the format back to the original (julian date):

function myFunction() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet1");
  const rng = sh.getRange("A1");
  rng.setNumberFormat("d.M.yyyy");
  SpreadsheetApp.flush();
  const dt = rng.getDisplayValue();
  rng.setNumberFormat("#")
  
  console.log(dt); // work with dt
}
Marios
  • 26,333
  • 8
  • 32
  • 52