MySQL converts timestamps directly to DateTime

Source: Internet
Author: User
Tags local time postgresql

Date is the parameter that needs to be processed (the parameter is a UNIX timestamp), can be a field name, or it can be a Unix timestamp string
The following '%y%m%d ' is primarily the formatting of the return value
For example:
Mysql>select from_unixtime (1249488000, '%y%m%d ')
->20071120
Mysql>select from_unixtime (1249488000, '%y year%m month%d ')
->2007 Year November 20
Unix_timestamp () is a time function that is opposite to it

Unix_timestamp (), Unix_timestamp (date)

If no parameter is called, returns a Unix timestamp (the number of seconds after the ' 1970-01-01 00:00:00 ' GMT) as an unsigned integer. If you call Unix_timestamp () with date, it returns the value of the parameter in the form of a number of seconds after the ' 1970-01-01 00:00:00 ' GMT. Date can be a date string, a DateTime string, a timestamp, or a number in the YYMMDD or YYYMMDD format of a local time.

For example:

Mysql> SELECT Unix_timestamp (); (Execution time: 2009-08-06-10:10:40)
->1249524739
mysql> SELECT unix_timestamp (' 2009-08-06 ');
->1249488000 [[email protected] ~]# mysql-e "Select Unix_timestamp (' date-i-d ' a day ago"); "
+------------------------------+
| Unix_timestamp (' 2011-03-02 ') |
+------------------------------+
| 1298995200 |
+------------------------------+ How to get the current UNIX timestamp (Unix timestamp) in different programming languages?
Java time
JavaScript Math.Round (New Date (). GetTime ()/1000)
GetTime () The unit of return value is milliseconds
Microsoft. net/c# Epoch = (DateTime.Now.ToUniversalTime (). Ticks-621355968000000000)/10000000
MySQL SELECT Unix_timestamp (now ())
Perl time
PHP time ()
PostgreSQL SELECT Extract (Epoch from now ())
Python first imports time and then Time.time ()
Ruby get UNIX timestamp: Time.now or Time.new
Show Unix timestamp: Time.now.to_i
SQL Server SELECT DATEDIFF (S, ' 1970-01-01 00:00:00 ', getUTCDate ())
Unix/linux Date +%s
Vbscript/asp DateDiff ("s", "01/01/1970 00:00:00", Now ())
Other operating systems
(If Perl is installed on the System) command line status: PERL-E "Print Time"
How to implement UNIX timestamp (Unix timestamp) in different programming languages → normal time?
Java String date = new Java.text.SimpleDateFormat ("Dd/mm/yyyy HH:mm:ss"). Format (new java.util.Date (Unix timestamp * 1000 ))
JavaScript first var unixtimestamp = new Date (Unix timestamp * 1000) then Commontime = Unixtimestamp.tolocalestring ()
Linux date-d @Unix Timestamp
MySQL from_unixtime (Unix timestamp)
Perl First my $time = Unix timestamp then my ($sec, $min, $hour, $day, $month, $year) = (localtime ($time)) [0,1,2,3,4,5,6]
PHP date (' R ', Unix timestamp)
PostgreSQL SELECT TIMESTAMP with time ZONE ' epoch ' + Unix TIMESTAMP) * INTERVAL ' 1 second ';
Python first imports time and then Time.gmtime (Unix timestamp)
Ruby time.at (Unix timestamp)
SQL Server DATEADD (s, Unix timestamp, ' 1970-01-01 00:00:00 ')
Vbscript/asp DateAdd ("s", Unix timestamp, "01/01/1970 00:00:00")
Other operating systems
(If Perl is installed on the System) command line status: Perl-e "Print scalar (localtime (Unix timestamp))" Example: Query member table for nearly three months user login SQL code SelectUid,userid,username,email,from_unixtime (lastvisit, '%y year%m month%d ') fromMembers whereLastvisit between Unix_timestamp (' 2010-01-06 ') and Unix_timestamp (' 2010-04-06 ');

Select Uid,userid,username,email,from_unixtime (lastvisit, '%y year%m Month%d ') from the members where lastvisit between unix_ TIMESTAMP (' 2010-01-06 ') and Unix_timestamp (' 2010-04-06 ');

MySQL converts timestamps directly to DateTime

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.