0

In my table, I have a field called created_at with data type timestamp and values are like 2016-12-30 00:30:10 and so on.

In my query, I get all those by a simple select * statement.

How can I get only the dates where it is equal to today's date?

I am using a framework called makoframework and the query builder is this:

$data = $query->table('customers')
->where('created_at', '=', //date today)
->all();

Any help would be much appreciated.

2
  • use DATE(created_at) hope it will work. Commented Dec 30, 2016 at 4:10
  • It says DATE(created_at) column is not found @SoniyaReddy Commented Dec 30, 2016 at 4:18

4 Answers 4

2

This will work

WHERE DATE(created_at) = CURDATE()

Sign up to request clarification or add additional context in comments.

Comments

2

Try

->where('DATE(created_at)', '=', '2016-12-30')

I'm sure about the query but I haven't used that framework so i'm not sure if it will pass it over to mysql as it is.

Use this for your framework

->whereRaw('DATE(created_at)', '=', '2016-12-30')

4 Comments

'DATE(created_at)' is counted as a column
That's fine mysql will know what to do with it
I get this Column not found: 1054 Unknown column 'Date(ph.created_at)' in 'where clause'
That most probably means the framework is sending that parameter in quotes. Use the raw query option and it will work like a charm
0

I don't know which framework you are using but in Core PHP you can use date() function to print the current date in a specific format.

 $data = $query->table('customers')
         ->where('DATE(created_at)', '=', date('Y-m-d'))
         ->all();

Comments

0

So I opened an issue in the framework's github site and the correct way to which is working is this:

$now = date('Y-m-d');
->where(new Raw('Date(ph.created_at)'), '=', $now)

Just remember to import mako\database\query\Raw

Thanks for all the help.

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.