Solved

compare timestamp to curdate() mysql

Posted on 2010-09-06
2
1,245 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
2 Comments
 
LVL 22

Accepted Solution

by:
Om Prakash earned 500 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now