1 SelectDate_format (Createtime,'%y-%m'),Count(*) fromTestwhere User =8 Group byDate_format (Createtime,'%y-%m');//Monthly Statistical Data2 SelectDate_format (Createtime,'%y-%m-%d'),Count(*) fromTestwhere User =8 Group byDate_format (Createtime,'%y-%m-%d');//Statistics by day
+---------------------------------+----------+|Date_format (Createtime,'%y-%m')| Count(*)|+---------------------------------+----------+| -- to | 1 || -- . | 1 || -- - | 5 || -- , | 1 |+---------------------------------+----------+4Rowsinch Set
Date_format (Date,format)
Formats the date value according to the format string. The following modifiers can be used in the format string:
%M month name (January ... December)
%W Week name (Sunday ... Saturday)
%d The date of the month with English prefixes (1st, 2nd, 3rd, etc.). )
%Y year, number, 4 bit
%y year, number, 2 bit
%a abbreviated weekday name (Sun ... Sat)
Number of days in the month of%d, number (00 ...). 31)
Number of days in%e month, number (0 ... 31)
%m Month, number (01 ... 12)
%c month, number (1 ... 12)
%b Abbreviated month name (Jan ... DEC)
%j Days of the year (001 ... 366)
%H hours (00 ... 23)
%k hours (0 ... 23)
%h hours (01 ... 12)
%I Hours (01 ... 12)
%l hours (1 ... 12)
%i minutes, Numbers (00 ... 59)
%r time, 12 hours (Hh:mm:ss [ap]m)
%T time, 24 hours (HH:MM:SS)
%s seconds (00 ... ()
%p am or PM
%w days in one weeks (0=sunday ...) 6=saturday)
%u Week (0 ... 52), here Sunday is the first day of the week
%u Week (0 ... 52), here Monday is the first day of the week
%% a text "%".
Supplemental SQL Server-like datepart usage
MySQL by month, grouped by day statistics