Solved

compare timestamp to curdate() mysql

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

710 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