Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timestamp query 2

Status
Not open for further replies.

rab54

Programmer
Jan 28, 2004
112
GB
OK Gurus -

How can I pull out all data for today from a timestamp field ?

eg select * from table where timestamp = now() or
select * from table where timestamp = date_add(now)

any ideas guys ??

cheers in advance

Rab
 
select * from table where timestamp = now()

will be too specific. It will only find those records which were entered of updated in the last second.

You might try a query like

select * from tablename where date_format(timestampcolumn, '%Y-%m-%d') = date_format(now(),'%Y-%m-%d')

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Cheers sir ! you are a star !

Rab
 
what about:
Code:
where timestampcolumn
    between current_date
        and date_add(current_date, interval 1 day)
my understanding is that if you perform any function on the column, mysql will not use the index on that column

so, instead of

... where function(col) = expression

you should always try to write the predicate as

... where col = function(expression)

rudy
SQL Consulting
 
rab54
If you think sleipnir's a star, then why not give him a star?

 
Each posting has a clickable footer *Thank xxxxxx for this valuable post." He's always at/near the top so he doesn't need it but he works very hard on these forums.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top