Kaic_supra
Kaic_supra

Reputation: 133

how do I know the minimum date in a query?

I have a column with various dates as timestamps!

"01/17/2014 08:25:13"

"01/17/2014 08:15:11"

"01/17/2014 09:55:12"

"01/17/2014 08:45:01"

...

...

how do I do a query to find the earliest date?

Upvotes: 0

Views: 60

Answers (1)

Denis de Bernardy
Denis de Bernardy

Reputation: 78591

Either:

select min(stamp) from tbl

Or:

select stamp from tbl order by stamp asc limit 1

The first can also be used as a window function, if you need it on an entire set without grouping.

If you need the date in the stamp, cast it:

select min(stamp::date) from tbl

Or:

select stamp::date from tbl order by stamp asc limit 1

Upvotes: 2

Related Questions