MySQL date format conversion using MySQL's date_format () for date format

Source: Internet
Author: User
Tags month name

Encounter a MySQL problem, table LOGSTATB the contents of the moment field is "year-month-day time: minutes: Seconds", you need to query matching "Month Day" or "Time: minute: Seconds" can data entry, this time can be implemented by the following SQL statement:

Select * from LOGSTATB where date_format (moment, '%y%m%d ') = ' 20080227 '(match "Month Day")
SELECT * from LOGSTATB where date_format (moment, '%h:%i:%s ') = ' 16:40:01 '(matches: minutes: Seconds ")

Date_format (date, format) can format date or date and time values according to format string, and return the result string. You can use Date_format () to format a date or datetime value to get the format you want. Format the date value according to the format string:

%s,%s two-digit seconds (00,01, ..., ())
%i Two-digit (00,01, ..., a)
% h two-digit hours, 24 small Time (00,01, ..., +)
%h,%I Two-digit hours, 12 hours (01,02, ..., 1)
%k hours, 24 hours (0,1, ..., 2)
%l Digital form of hours, 12 hours (24,, ..., +)
% T time-of-day form Type (h h:m m:s s)
%r 12-hour time form (Hh:mm:ss am or hh:mm:ss PM)
%p am or P m
% W the name of each day of the week (S u n d a y, Monday, ..., s aturday)
% a abbreviation for the name of each day of the week (Sun, Mon, ..., Sat)
%d two digits indicates the number of days in the month (xx,%, ..., +)
%e numbers represent the number of days in the month (1, 2, ..., 31 )
% D The English suffix indicates the number of days in the month (1st, 2nd, 3rd, ...).
%w The number of days in the week (0 = S u n d a y, 1=monday, ..., 6=saturday)
%j Three-digit number of days in the year (001, 002, ..., 366)
% u week (0, 1, 52), where Sunday is the first day of the week
%u week (0, 1, 52), where Monday is the first day of the week
%M month name (J a n u a r y, February, ..., December)
%b abbreviated month name ( J a n u a r y, February, ..., December)
%m Two-digit month (in. 1, 2, ..., y)
%c number represents the month (+)
%Y four-digit table Year
%y Two-digit year
% Direct value "%"

 

MySQL date format conversion using MySQL's date_format () for date format conversions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.