19 August 2008

system date, time และ timestamp

สำหรับ DB2
อยากได้ system date time หรือ timestamp จาก SQL statement ให้ใช้คำสั่ง

  • CURRENT DATE
  • CURRENT TIME
  • CURRENT TIMESTAMP

ตัวอย่างเช่น


SELECT *, CURRENT TIMESTAMP
FROM SCHEMA.TABLE_A;

SELECT CURRENT DATE
FROM SYSIBM.SYSDUMMY1
FETCH FIRST 1 ROWS ONLY;

3 comments:

  1. ถ้าเป็นของ Informix ใช้คำสั่ง

    select current from systables where tabid=99;
    select today from systables where tabid=99;

    Informix มี function เกี่ยวกับ date/time อีกมากมาย ที่ http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqls.doc/sqls1035.htm

    ReplyDelete
  2. ถ้าเป็นของ Teradata ใช้คำสั่ง

    select date; -- system date
    select time; -- system time
    select current; -- system timestamp

    ReplyDelete
  3. ถ้าเป็นของ Oracle ใช้คำสั่ง

    select sysdate from dual; --system timestamp

    อยากได้ date หรือ time ก็ใช้ function to_date, to_char แปลงเอาอีกที

    ReplyDelete