How can I get a datetime from database but without hours and minutes? Format in database e.g 2016-03-28 15:55:00 I would like get this record if I type in SQL format y-m-d.
You haven't mentioned the RDBMS you're using. I presume it must be either be MySQL or SQL Server.
MySQL:
Here's the docoumentation in the manual : DATE()
You can use it as such (illustration) :
SELECT DATE('2003-12-31 01:02:03')
Which will yield you : 2003-12-31
Hope this helps!!!
EDIT : I understand you want to apply filtering on it (i.e WHERE
clause). This is one-way you can do it.
You can use this :
SELECT DATE(COLUMN_NAME)
FROM TABLE_NAME
WHERE DATE_FORMAT(COLUMN_NAME, '%Y %m %d') = DATE_FORMAT('2016-03-28', '%Y %m %d')
You can check it out on this fiddle here -> SQL Fiddle
Hope this helps!!!
You can use this SQL statement:
SELECT date(dateTime) From table
You would use date()
in a where
clause:
where date(col) = '2016-03-28'
Or, what is better for performance reasons (because the engine can use an index if available):
where date >= '2016-03-28' and
date < date_add('2016-03-28', interval 1 day)