3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Google Spreadsheet上の日付と時間からシリアル値を得る関数

Last updated at Posted at 2017-01-10

Google スプレッドシートの別々のセルにある日付と時間からシリアル値を得る関数

 ある日時とある日時の大小を比較する時,シリアル値を合成して比較できると便利。

テンプレート

function main(){
  途中略
  var date = getValue(masterSheet, row1, column1);//セルでは「2017/01/13」
  var time = getValue(masterSheet, row2, column2);//セルでは「13:13:00」
  
  var serial = getSerial(date,time);//シリアル値を日付と時間からゲット
  var date2 = getDate(serial);//日付をシリアル値から取り出す, Fri Jan 13 2017
  var time2 = getTime(serial);//時刻をシリアル値から取り出す, 13:13:00
}



function getSerial(date,time){//日付と時間からシリアル値をゲット
  var serial = new Date(date.toString().slice(0,16)+time.toString().slice(16));
  return serial;
}

function getTime(serialValue){//シリアル値から時間を取り出す,シリアル値は「1899年12月30日午前0時」からの経過ミリ秒(のはず)
  var str = serialValue.toString();//(例:'Sat Oct 29 2016 16:05:42 GMT+0900 (JST)')
  var strings = str.split(' ');
  return strings[4];
}

function getDate(serialValue){//シリアル値から年月日を取り出す
  var str = serialValue.toString();//(例:'Sat Oct 29 2016 16:05:42 GMT+0900 (JST)')
  var strings = str.split(' ');
  return strings[0] +' '+ strings[1] +' '+ strings[2] +' '+ strings[3];
}

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?