MySQL Forums
Forum List  »  PHP

Re: Date - unix_timestamp
Posted by: Rick James
Date: February 07, 2010 12:13PM

Here's a table with just a TIMESTAMP column:
CREATE TABLE `ts` (
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8

# Here are some values in that table:
mysql> select ts, MONTH(ts) from ts;
+---------------------+-----------+
| ts                  | MONTH(ts) |
+---------------------+-----------+
| 2009-03-19 19:00:26 |         3 |
| 2009-03-19 19:00:26 |         3 |
| 2009-03-19 19:00:26 |         3 |
| 2009-03-24 22:45:01 |         3 |
| 2009-03-27 19:32:29 |         3 |
| 2009-03-27 20:32:29 |         3 |
| 2009-03-27 18:32:29 |         3 |
| 2010-02-07 10:02:32 |         2 |
| 2009-08-07 10:03:02 |         8 |
+---------------------+-----------+

# by comparison, here is the current month:
mysql> select MONTH(now());
+--------------+
| MONTH(now()) |
+--------------+
|            2 |
+--------------+

# Sounds like you want something like:
select * from table where MONTH(datefield) = MONTH(NOW());

This is ambiguous and/or contradictory; please rephrase:
"able to do things at certain time, ie. every 6 hours starting at midnignt"

To see if it is currently between midnight and 6am (inclusive), you could do:
WHERE CURTIME() BETWEEN '00:00' and '06:00'

Everything you need is here (granted, it is a lot to digest):
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

Options: ReplyQuote


Subject
Written By
Posted
February 04, 2010 02:38PM
February 06, 2010 12:27AM
February 07, 2010 11:33AM
Re: Date - unix_timestamp
February 07, 2010 12:13PM
February 07, 2010 09:21PM
February 07, 2010 09:43PM
February 07, 2010 10:16PM
February 07, 2010 10:22PM
February 07, 2010 10:31PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.