टेबल बनाएं
mysql> create table DemoTable (
-> PunchOut timestamp,
-> PunchStatus tinyint(1)
-> );
Query OK, 0 rows affected (0.51 sec)
रिकॉर्ड्स डालें
mysql> insert into DemoTable values('2019-01-31 6:30:10',1);
Query OK, 1 row affected (0.22 sec)
mysql> insert into DemoTable values('2019-02-06 4:10:13',0);
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('2018-12-16 03:00:30',0);
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values('2016-11-25 02:10:00',1);
Query OK, 1 row affected (0.22 sec)
सभी रिकॉर्ड्स देखें
mysql> select * from DemoTable;
+---------------------+-------------+ | PunchOut | PunchStatus | +---------------------+-------------+ | 2019-01-31 06:30:10 | 1 | | 2019-02-06 04:10:13 | 0 | | 2018-12-16 03:00:30 | 0 | | 2016-11-25 02:10:00 | 1 | +---------------------+-------------+ 4 rows in set (0.00 sec)
टाइमस्टैम्प फ़ील्ड अपडेट करने का क्वेरी (PunchStatus=0 वाली पंक्तियों के लिए वर्तमान तिथि/समय सेट करें)
नोट: वर्तमान तिथि और समय 2019-06-30 13:43:45 है
mysql> update DemoTable set PunchOut=now() where PunchStatus=0; Query OK, 2 rows affected (0.19 sec) Rows matched: 2 Changed: 2 Warnings: 0
फिर से जांचें
mysql> select * from DemoTable;
+---------------------+-------------+ | PunchOut | PunchStatus | +---------------------+-------------+ | 2019-01-31 06:30:10 | 1 | | 2019-06-30 13:43:45 | 0 | | 2019-06-30 13:43:45 | 0 | | 2016-11-25 02:10:00 | 1 | +---------------------+-------------+ 4 rows in set (0.00 sec)
मुख्य बिंदु:
NOW()- वर्तमान तिथि और समय लौटाता हैCURRENT_TIMESTAMP- समान कार्यTIMESTAMPकॉलम स्वचालित रूप से अपडेट हो सकता है यदिON UPDATE CURRENT_TIMESTAMPपरिभाषित हो