Welcome Guest, Not a member yet? Register   Sign In
MYSQL and UNIX timestamps...
#3

[eluser]mddd[/eluser]
With LIKE, you are treating the date as a string and comparing against that. So Mysql will compare '1264163400' with '2010-01' and that will not match.
Assuming the database has to stay the same (so you will keep using Unix timestamps) I would do this:
Code:
SELECT * FROM events WHERE YEAR((FROM_UNIXTIME(date))=2010 AND MONTH(FROM_UNIXTIME(date))=1
So, you turn the number into a real date and then use Mysql's date functions to check that date.

But in my opinion it would be even better just to use a Date field (or Datetime if times are important). Then you would not have this issue. You can just as easily compare dates as timestamp integers. So why not use the smartness of Mysql for your date/time needs.


Messages In This Thread
MYSQL and UNIX timestamps... - by El Forum - 04-07-2010, 06:53 PM
MYSQL and UNIX timestamps... - by El Forum - 04-07-2010, 11:32 PM
MYSQL and UNIX timestamps... - by El Forum - 04-08-2010, 12:20 AM
MYSQL and UNIX timestamps... - by El Forum - 04-08-2010, 07:31 AM
MYSQL and UNIX timestamps... - by El Forum - 04-08-2010, 07:38 AM
MYSQL and UNIX timestamps... - by El Forum - 04-08-2010, 08:58 AM
MYSQL and UNIX timestamps... - by El Forum - 04-08-2010, 09:04 AM
MYSQL and UNIX timestamps... - by El Forum - 04-08-2010, 10:15 AM
MYSQL and UNIX timestamps... - by El Forum - 04-08-2010, 05:19 PM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 12:48 AM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 05:45 AM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 05:56 AM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 06:01 AM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 06:15 AM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 06:38 AM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 06:43 AM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 06:56 AM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 07:00 AM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 07:11 AM
MYSQL and UNIX timestamps... - by El Forum - 04-09-2010, 06:14 PM
MYSQL and UNIX timestamps... - by El Forum - 04-12-2010, 12:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB