Reputation: 115
I have a Google sheet with datetime numbers in the following format: 42,385.744166666700
I am writing a script and I want to extract the time from these numbers in the format HH:MM. The above number should return 17:51.
I tried this code but does not work:
function extractMicrosTime(DateTimeNumber) {
var DateNumber = new Date(DateTimeNumber);
var hours = DateNumber.getHours();
var minutes = DateNumber.getMinutes();
return hours + ":" + minutes;
}
Upvotes: 0
Views: 2662
Reputation: 46794
For info, this can be done with script as well. Example below for column A
function formatColumn() {
var sh = SpreadsheetApp.getActiveSheet();
var col = sh.getRange('A1:A');
col.setNumberFormat('dd/MM/yyyy HH:mm:ss');
}
Upvotes: 1
Reputation: 1713
Your function will work if you format the source cell as Date time.
If you do use it raw it returns 19:0
Upvotes: 0