MySQL storage date is long, judging the time size

Source: Internet
Author: User

Change the sales status of April 20 to the current time period to unsold (1), the sales time to null (0) UPDATE hy_car_detail hcd SET hcd.sales_date = ", Hcd.sales_status = ' 1 ' where HCD . car_id in (Select hc.car_id from Hy_car HC WHERE hc.car_date between ( select Unix_timestamp (' 2016-04-20 00:00:00 ') "an" D (SELECT unix_timestamp ())Knowledge Points: The date in MySQL is converted to a long type (converted into seconds storage) for easy query use 1, convert time to seconds: 1.1:SELECT Unix_timestamp ()Gets the current time converted to the number of seconds 1.2:unix_timestamp (' 2016-04-20 00:00:00 ')Gets the number of seconds of the specified date 2, converting the number of seconds to a date format: 2.1:SELECT from_unixtime (1388776825)3, you can also increase the time format, the use of the following:

SELECT from_unixtime (1388776825, '%y%m%d ') results: 20140104

SELECT from_unixtime (1388776825, '%y year%m month%d ') results: January 2014 4

4. Convert string to date format MySQL similar to To_char () to_date () function

MySQL date and Character conversion method

Date_format (date, '%y-%m-%d ')--------------To_char () in >oracle;

Str_to_date (date, '%y-%m-%d ')--------------to_date () in >oracle;

%Y: Represents a 4-digit year

%y: Represents the year of 2

%m: Represents the month, in the form of (01 ... 12)

%c: Represents the month in the format of (1 ... 12)

%d: Represents the number of days in the month in the format (00 ...). 31)

%e: Represents the number of days in the month in the format (0 ...). 31)

%H: Represents the hour, in the form of (00 ... 23)

%k: Represents the hour, in the form of (0 ... 23)

%h: Represents the hour, in the form of (01 ... 12)

%I: Represents the hour, in the form of (01 ... 12)

%l: Represents the hour, in the form of (1 ... 12)

%i: Represents minutes, in the form of (00 ... 59)

%r: Represents the time, in the format of 12 hours (Hh:mm:ss [ap]m)

%T: Represents the time, in the format of 24 hours (HH:MM:SS)

%s: represents seconds in the format (00 ...). 59)

%s: represents seconds in the format (00 ...). 59)

SELECT date_format (20130111191640, '%y-%m-%d%h:%i:%s ')

Date_format (20130111191640, '%y-%m-%d%h:%i:%s ')

MySQL storage date is long, judging the time size

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.