MYSQL function: DATE_FORMAT
example:
select DATE_FORMAT(create_time,
'%Y%m%d') days,count(caseid) count from tc_case group by days;
select DATE_FORMAT(create_time,'%Y%u') weeks,count(caseid) count from tc_case group by weeks;
select DATE_FORMAT(create_time,'%Y%m') months,count(caseid) count from tc_case group by months;
select DATE_FORMAT(create_time,'%Y%u') weeks,count(caseid) count from tc_case group by weeks;
select DATE_FORMAT(create_time,'%Y%m') months,count(caseid) count from tc_case group by months;
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 Day of the month with an English prefix (1st, 2nd, 3rd, etc.)
- %Y year, numeric, 4 digits
- %y year, number, 2 digits
- %a Abbreviated week name (Sun...Sat)
- %d day of month, number (00...31)
- %e Day of month, number (0...31)
- %m month, number (01...12)
- %c month, number (1...12)
- %b Abbreviated month name (Jan...Dec)
- %j Day 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 minute, number (00...59)
- %r time, 12 hours (hh:mm:ss [AP]M)
- %T time, 24 hours (hh:mm:ss)
- %S seconds (00...59)
- %s seconds (00...59)
- %p AM or PM
- %w the number of days in a week (0=Sunday ...... 6=Saturday)
- %U week (0...52), where Sunday is the first day of the week
- %u week (0...52), where Monday is the first day of the week
- %% A literal "%".