10

I have a table.

enter image description here

as you can see created_date column is timestamp field. now on selection i want to consider only date value. for e.g if i want to make selection of rows from today i want to do something like:-

select * from audit_logs where created_date = '2018-11-28';

the above query returns null. is it possible to make selection this way ?

2
  • you can use LIKE instead Commented Nov 28, 2018 at 5:59
  • 1
    I can't read that tiny image text... Please, use formatted text instead of images the next time. Commented Nov 28, 2018 at 6:21

2 Answers 2

16

You can use date() function

select * from audit_logs where date(created_date) = '2018-11-28'
Sign up to request clarification or add additional context in comments.

3 Comments

thanks. i didn't knew about this date() function. it is working.
yes sure, it asks to wait for some minutes before i can accept it.
@sagarlimbu: it's not really a function. It's a different way to write a type cast. It's the same as created_date::date or cast(created_data as date)
0

An alternative function is date_trunc(text, timestamp), if you want more flexibility (truncate to hour, for example). Check out the postgres documentation (which is great) for all the date/time functions: https://www.postgresql.org/docs/current/functions-datetime.html

You do get a timestamp back instead of date, mind.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.