Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this sql where statement correct?

I have 10 rows for today's date but my select statement based on date dosen't seem to work....

SELECT Id,WirelessId,RegNo,DriverName1,MobileNo1,DriverName2,MobileNo1 from
 DailySchedule where IsDeleted=0 and CreatedDate='2010-05-28'

Any suggestion...

like image 943
Priyaa Muthuraman Avatar asked Feb 06 '26 02:02

Priyaa Muthuraman


2 Answers

Only if the dates assigned to them are midnight today. It might be better to do:

CreatedDate BETWEEN '2010-05-28 00:00' AND '2010-05-29 00:00'
like image 185
Dave D Avatar answered Feb 08 '26 16:02

Dave D


If you want all the entries for May 28th I would do

and CreatedDate >='20100528'
and CreatedDate < '20100529'

Notice the safe ISO format (YYYYMMDD) no dashes

Also take a look at How Does Between Work With Dates In SQL Server? to see why between can not give you all the results you want

like image 31
SQLMenace Avatar answered Feb 08 '26 16:02

SQLMenace