2

I have a record of data with unix time date in it

i want to select the row based on the date/month/year only (not with time)

currently Im using something like this

select * 
  from tablename 
 where date > '$today' 
   and date < '$tomorow' 
 LIMIT 1; 

how ever this is not that accurate if the $today and $tomorrow have different time (but same date)

is there any better way to do this?

0

2 Answers 2

2
... WHERE DATE(FROM_UNIXTIME(date)) > DATE(FROM_UNIXTIME('$today')) ...

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

Sign up to request clarification or add additional context in comments.

1 Comment

This would cause the query to use a table scan, which may not be desirable if the table is very large.
0

Use this statement :

 SELECT * FROM TABLE WHERE DATE LIKE 'YEAR-MOTH-DATE%'.

For example I use this for my case:

 SELECT * FROM USER_MANAGER u WHERE DATE_REGISTER LIKE '2012-09-08%';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.