Solved

compare timestamp to curdate() mysql

Posted on 2010-09-06
2
1,252 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

910 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

19 Experts available now in Live!

Get 1:1 Help Now