Skip to content

Instantly share code, notes, and snippets.

@HungHT1890
Last active July 26, 2025 23:22
Show Gist options
  • Select an option

  • Save HungHT1890/dfb273164df9f1eb4bc55f7056d80592 to your computer and use it in GitHub Desktop.

Select an option

Save HungHT1890/dfb273164df9f1eb4bc55f7056d80592 to your computer and use it in GitHub Desktop.
Tạo tool server bằng google sheet + app script

MÃ CODE

function getSheetData() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const data = sheet.getDataRange().getValues();
  const results = [];

  // ⏰ Lấy timestamp 00:00:00 hôm nay
  const now = new Date();
  now.setHours(0, 0, 0, 0);  // reset giờ về 0

  for (let i = 1; i < data.length; i++) {
    const row = data[i];

    const name = row[0] ? row[0].toString() : "";
    const key = row[1] ? row[1].toString() : "";
    const dateStr = row[2] ? row[2].toString() : "";
    const note = row[3] ? row[3].toString() : "";

    let status = false;

    if (dateStr.match(/^\d{2}\/\d{2}\/\d{4}$/)) {
      const [day, month, year] = dateStr.split('/').map(Number);
      const expireDate = new Date(year, month - 1, day);
      expireDate.setHours(0, 0, 0, 0);  // cũng set về 00:00:00

      status = expireDate >= now;
    }

    results.push({
      name,
      key,
      date: dateStr,
      note,
      status
    });
  }

  Logger.log(results);
  return results;
}

function doGet(e) {
  const results = getSheetData();
  return ContentService
    .createTextOutput(JSON.stringify(results))
    .setMimeType(ContentService.MimeType.JSON);
}

MẪU SHEET

image

VIDEO HƯỚNG DẪN https://youtu.be/gV8nnO8SQLM

VIDEO DỰ PHÒNG

https://drive.google.com/file/d/1cg8H_NLECr6Xul1HZYsUo4IEh_c_8Bha/view?usp=sharing

LIÊN HỆ

Telegram

Gmail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment