2 Replies - 137 Views - Last Post: 01 April 2019 - 01:17 AM

#1 juniordev101   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-March 19

DateTime not working with where clause

Posted 30 March 2019 - 04:40 AM

Hi guys,

I may be explaining this quite simple, but i want to make sure i am asking my question right.

I'm using the Mysql manual to format dates

When i run this query it works fine:

 
select date_format (date_time,'%d-%m-%Y'), AVG(Total), sum(Total_ly),  AVG ((Total + Total_ly)/2) from Transaction  Group By date_time;



So, i want to add a WHERE clause to get dates between a specific period like the follwoing:
WHERE date_time >=  '22-03-2019' AND date_time <= '24-03-2019' 



So, my question why does everything return null, when i put the where clause in ?
Any suggestions appreciated !!!
P.S. Im very new to all this so sorry if its simple

Is This A Good Question/Topic? 0
  • +

Replies To: DateTime not working with where clause

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15106
  • View blog
  • Posts: 60,409
  • Joined: 12-June 08

Re: DateTime not working with where clause

Posted 30 March 2019 - 08:03 AM

The SELECT is just about output formatting. You would either need to use the same 'date_format' function in the WHERE clause or just use regular datetime formatting for MYSQL.

Don't forget you can look at using BETWEEN.

https://www.w3school...sql_between.asp
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4230
  • View blog
  • Posts: 13,409
  • Joined: 08-June 10

Re: DateTime not working with where clause

Posted 01 April 2019 - 01:17 AM

View Postjuniordev101, on 30 March 2019 - 01:40 PM, said:

So, i want to add a WHERE clause to get dates between a specific period like the follwoing:
WHERE date_time >=  '22-03-2019' AND date_time <= '24-03-2019' 



Neither of those is a valid MySQL timestamp. Cf. https://dev.mysql.co...n/datetime.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1