Mawg
Mawg

Reputation: 40205

How to get the last timestamp for a given date?

I have a timestamp column in my table. I want to pass a date as a paramater and run a search which returns the final row for that day (MAX timestamp, given the :date parameter).

My query currently looks like

SELECT some columns
FROM table_1
JOIN table_2 ON column_name

and I want to add a WHERE times_stamp something :date something something ... I'm stuck.

What is my where clause ?

The first part of the search is exceedingly complex, but works, so I won't bother with it here, nor with the data, since it is not relevant; just know that there is atime_stamp column and I want the final one for a given date..

I think that I am looking at soemthing like

WHERE DATE(t.time_stamp) = :date ORDER BY p.time_stamp DESC LIMIT 1

but I just don't know how to formulate it.

Upvotes: 0

Views: 313

Answers (1)

juergen d
juergen d

Reputation: 204924

SELECT some_columns
FROM table_1 t1
JOIN table_2 t2 ON t1.column_name = t2.column_name
where date(times_stamp) = :date
order by times_stamp desc
limit 1

Upvotes: 1

Related Questions