php mysql php mysql date and time function set

Source: Internet
Author: User
Tags month name php mysql
Collect the full MySQL date and MySQL time functions
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 ... 59)
%s seconds (00 ... 59)
%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
Percent of a text "%".
All other characters are not interpreted as being copied into the results.
Mysql> Select Date_format (' 1997-10-04 22:23:00 ', '%W%M%Y ');
' Saturday October 1997 '
Mysql> Select Date_format (' 1997-10-04 22:23:00 ', '%h:%i:%s ');
' 22:23:00 '
Mysql> Select Date_format (' 1997-10-04-22:23:00 ',
'%d%y%a%d%m%b%j ');
4th Sat Oct 277 '
Mysql> Select Date_format (' 1997-10-04-22:23:00 ',
'%H%k%I%r%T%s%w ');
-10:23:00 PM 22:23:00 00 6 '
In MySQL3.23,% is required before the format modifier character. In the earlier version of MySQL,% is optional.
Time_format (Time,format)
This is used like the Date_format () function above, but the format string can contain only those formatting modifiers that handle hours, minutes, and seconds.
Other modifiers produce a null value or 0.
Curdate ()
 
Current_date
Returns today's date value in ' Yyyy-mm-dd ' or YYYYMMDD format, depending on whether the function is used in a string or a numeric context.
Mysql> select Curdate ();
' 1997-12-15 '
Mysql> Select curdate () + 0;
19971215
Curtime ()
 
Current_time
Returns the current time value in ' HH:MM:SS ' or HHMMSS format, depending on whether the function is used in a string or in the context of a number.
Mysql> select Curtime ();
' 23:50:26 '
Mysql> Select Curtime () + 0;
235026
Now ()
 
Sysdate ()
 
Current_timestamp
Returns the current date and time in ' Yyyy-mm-dd HH:MM:SS ' or YYYYMMDDHHMMSS format, depending on whether the function is in a string or a number
Context is used.
Mysql> Select Now ();
' 1997-12-15 23:50:26 '
Mysql> Select now () + 0;
19971215235026
Unix_timestamp ()
 
Unix_timestamp (date)
Returns a UNIX timestamp (the number of seconds from ' 1970-01-01 00:00:00 ' GMT) if no argument is called. If Unix_timestamp () is called with a date parameter, it returns the value of the second starting at ' 1970-01-01 00:00:00 ' GMT. Date can be a date string, a DateTime string, a timestamp, or a number in the local time in YYMMDD or YYYYMMDD format.
Mysql> select Unix_timestamp ();
882226357
Mysql> Select Unix_timestamp (' 1997-10-04 22:23:00 ');
875996580
When Unix_timestamp is used in a timestamp column, the function will accept the value directly, without the implied "String-to-unix-timestamp" transform http://www.knowsky.com/.
From_unixtime (Unix_timestamp)
Returns the value represented by the Unix_timestamp parameter in the ' Yyyy-mm-dd HH:MM:SS ' or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or in a numeric context.
Mysql> Select From_unixtime (875996580);
' 1997-10-04 22:23:00 '
Mysql> Select From_unixtime (875996580) + 0;
19971004222300
From_unixtime (Unix_timestamp,format)
Returns a String representing the Unix time token, formatted according to the format string. FORMAT can contain the same modifiers as the entries listed in the Date_format () function.
Mysql> Select From_unixtime (Unix_timestamp (),
'%Y%d%M%h:%i:%s%x ');
' 1997 23rd December 03:43:30 X '
Sec_to_time (seconds)
Returns the seconds parameter, changing to hours, minutes, and seconds, formatted with a value of ' HH:MM:SS ' or HHMMSS, depending on whether the function is used in a string or in a numeric context.
Mysql> Select Sec_to_time (2378);
' 00:39:38 '
Mysql> Select Sec_to_time (2378) + 0;
3938
Time_to_sec (Time)
Returns the time parameter, converted to seconds.
Mysql> Select Time_to_sec (' 22:23:00 ');
80580
Mysql> Select Time_to_sec (' 00:39:38 ');
2378

The above describes the PHP mysql php mysql date and time function set, including the content of PHP MySQL, I hope to be interested in PHP tutorial friends helpful.

  • 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.