Select only date from datetime?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Select only date from datetime?

Post by GeXus »

Is there a function i should use to return the date only from a datetime field?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Yes, if you format your date with the mysql date_format() function you can group/sort/count by a specific date.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

date(yourdatetimefield)
ex:

Code: Select all

mysql> select date(now());
+-------------+
| date(now()) |
+-------------+
| 2006-05-14  |
+-------------+
1 row in set (0.03 sec)
Post Reply