MySQL turns timestamps into common time formats
In MySQL, the storage type of a time field is int (11), and how to convert it into a character type, for example, to store 13270655222, needs to be converted to YYYY-MM-DD form.
Use the From_unixtime function, as follows:
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.
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 "%".
For example:
SELECT From_unixtime (1422720000'%y-%m-%d%T'
The output is:
- - Geneva - on xx:xx
How do I convert a date type to a timestamp? In fact, it is simply a matter of converting the date to a UNIX timestamp function: Unix_timestamp ().
Use the Unix_timestamp function, as follows:
SELECT unix_timestamp (' 2006-11-04 12:23:00 ');
For example:
SELECT Unix_timestamp ('2006-One-one-all: £ º');
The output is:
1162614180
Other than that
Now ()//Current Time sysdate ()//Current TimeCurrent_timestampin'YYYY-MM-DD HH:MM:SS'or the YYYYMMDDHHMMSS format returns the current date and time, depending on whether the function is used in a string or in the context of a number. MySQL> SelectNow (); - '1997-12-15 23:50:26'MySQL> SelectNow ()+ 0; - 19971215235026
sec_to_time (seconds) returns the seconds parameter, changing to hours, minutes, and seconds, with values'HH:MM:SS'or HHMMSS formatting, depending on whether the function is used in a string or in a numeric context. MySQL> SelectSec_to_time (2378); - '00:39:38'MySQL> SelectSec_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
MySQL timestamps convert each other