Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

compare timestamp to curdate() mysql

Posted on 2010-09-06
2
Medium Priority
?
1,266 Views
Last Modified: 2012-05-10
Hi,
I have a column that is of type "timestamp" in format of 2010-09-04 22:24:19 .  I need to run a process where I check today's date against any records that have been created today already (marked by timestamp).  

So essentially if i do select curdate(); it'll give me back 2010-09-06.  I want to compare that to the timestamp to see if this is the same day (so ignore the hh:mm:ms).

I dont want to do substring(TS, 1,10 ) where I'll have 2010-09-04 and i'll be able to compare strings... I want to do a DATE comparison.

Is this possible somehow?

Thanks,
0
Comment
Question by:Squadless
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
Om Prakash earned 2000 total points
ID: 33612644
Try adding the following in where clause:
WHERE DATE(date_field) = CURDATE();
0
 
LVL 6

Expert Comment

by:nasirbest
ID: 33612733
If you want a really simple solution then don't drop hh:mm:ms part, just use it with DATE_FORMATE function and put custom value for hh:mm:ss to define day range. see following example
SELECT * FROM tbl_name WHERE 
date_column > DATE_FORMAT(NOW(), '%Y-%m-%d 00:00:00') AND 
date_column < DATE_FORMAT(NOW(), '%Y-%m-%d 23:59:59');

Open in new window

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question