from unix-time, to unix-time, sql examples

 

mysql> select now();
 +---------------------+
 | now()               |
 +---------------------+
 | 2009-01-31 21:54:36 |
 +---------------------+
 1 row in set (0.00 sec)

 

mysql> select unix_timestamp(now());
 +-----------------------+
 | unix_timestamp(now()) |
 +-----------------------+
 |            1233435200 |
 +-----------------------+
 1 row in set (0.00 sec)
mysql> select from_unixtime(1233435200);
 +---------------------------+
 | from_unixtime(1233435200) |
 +---------------------------+
 | 2009-01-31 21:53:20       |
 +---------------------------+
 1 row in set (0.00 sec)
mysql> select count(*) from sessions where timestamp > unix_timestamp(now() - interval 31 day);
 +----------+
 | count(*) |
 +----------+
 |     8711 |
 +----------+
 1 row in set (0.06 sec)
mysql> select count(*) from sessions where timestamp > unix_timestamp("2009-01-01 00:00:00") and timestamp < unix_timestamp("2009-01-31 00:00:00");
 +----------+
 | count(*) |
 +----------+
 |     8407 |
 +----------+
 1 row in set (0.08 sec)
more info: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image

Subscribe without commenting