Thep Excel

$now – อ็อบเจ็กต์ Luxon สำหรับวันที่และเวลาปัจจุบัน

$now เป็นอ็อบเจ็กต์ Luxon DateTime ที่คืนค่า timestamp ปัจจุบัน (เทียบเท่า DateTime.now()) รองรับการจัดรูปแบบด้วย .toFormat(), การคำนวณด้วย .plus()/.minus(), และการแปลงเขตเวลาด้วย .setZone() เหมาะสำหรับสร้าง timestamp แม่นยำในการบันทึกข้อมูล

=$now

By ThepExcel AI Agent
16 December 2025

Function Metrics


Popularity
9/10

Difficulty
1/10

Usefulness
9/10

Syntax & Arguments

=$now

How it works

บันทึกเวลาการทำงาน

ทำการบันทึกเวลาแม่นยำเมื่อกระทำการหรือบันทึกข้อมูล

วัดระยะเวลา

วัดเวลาที่ใช้ในการประมวลผลหรือการทำงาน

Examples

ตัวอย่างที่ 1: จัดรูปแบบวันที่และเวลา
{{ $now.toFormat('yyyy-MM-dd HH:mm:ss') }}
จัดรูปแบบเวลาปัจจุบันเป็น timestamp แบบอ่านง่าย ใช้ .toFormat() พร้อม pattern ที่ต้องการ
n8n Formula:

={{ $now.toFormat('yyyy-MM-dd HH:mm:ss') }}

Result:

2024-12-16 14:30:52

ตัวอย่างที่ 2: สร้างชื่อไฟล์พร้อมวันที่
{{ 'report_' + $now.toFormat('yyyy-MM-dd') + '.csv' }}
ใช้ $now.toFormat() ในการสร้างชื่อไฟล์ที่มีวันที่ เหมาะสำหรับการสร้างรายงานประจำวัน
n8n Formula:

={{ 'report_' + $now.toFormat('yyyy-MM-dd') + '.csv' }}

Result:

report_2024-12-16.csv

ตัวอย่างที่ 3: แปลงเขตเวลา (Timezone)
{{ $now.setZone('Asia/Bangkok').toFormat('yyyy-MM-dd HH:mm') }}
ใช้ .setZone() เพื่อแปลงเวลาไปยังเขตเวลาที่ต้องการ เช่น Asia/Bangkok หรือ UTC+7
n8n Formula:

={{ $now.setZone('Asia/Bangkok').toFormat('yyyy-MM-dd HH:mm') }}

Result:

2024-12-17 01:30

ตัวอย่างที่ 4: บันทึก timestamp ในฐานข้อมูล
{{ {event: 'user_login', timestamp: $now.toISO()} }}
ใช้ .toISO() เพื่อสร้าง timestamp ในรูปแบบ ISO 8601 มาตรฐาน เหมาะสำหรับบันทึกในฐานข้อมูล
n8n Formula:

={{ {event: 'user_login', timestamp: $now.toISO()} }}

Result:

{event: 'user_login', timestamp: '2024-12-16T14:30:52.414Z'}

FAQs

$now และ $today ต่างกันอย่างไร?

$now คืนค่าวันที่และเวลาปัจจุบันพร้อม timestamp แม่นยำ ส่วน $today คืนค่าวันที่เที่ยงคืน (00:00:00) เหมาะสำหรับการเปรียบเทียบวันที่

ใช้ .toFormat() หรือ .toISO() ดีกว่ากัน?

ใช้ .toISO() สำหรับบันทึกในฐานข้อมูล (มาตรฐานสากล) และ .toFormat() สำหรับแสดงผลหรือชื่อไฟล์ที่ต้องการรูปแบบเฉพาะ

$now ใช้เขตเวลาอะไร?

n8n ใช้เขตเวลา America/New_York เป็นค่าเริ่มต้น สามารถเปลี่ยนได้ด้วย .setZone() เช่น $now.setZone(‘Asia/Bangkok’)

format pattern ที่ใช้บ่อยมีอะไรบ้าง?

yyyy-MM-dd (2024-12-16), HH:mm:ss (14:30:52), yyyy-MM-dd HH:mm:ss (timestamp เต็ม), EEEE (วันในสัปดาห์), MMMM dd, yyyy (December 16, 2024)

Resources & Related

Additional Notes

$now เป็นอ็อบเจ็กต์ Luxon DateTime ที่มีค่า timestamp ปัจจุบัน (เทียบเท่า DateTime.now()) คืนค่าวันที่และเวลาปัจจุบันพร้อม milliseconds ในรูปแบบ ISO 8601 ใช้ร่วมกับ .toFormat() เพื่อจัดรูปแบบวันที่เวลา

Leave a Reply

Your email address will not be published. Required fields are marked *