Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of changing time of mysql verchar

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the method of mysql verchar time transfer, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

In mysql, you can use the str_to_date function to convert verchar to a time type. The syntax of this function is "Str_to_date (col.pattern)", where the parameter col is the field or content that needs to be formatted.

Replace the 1.date type with the varchar type

Use the date_format function for conversion, using the

Date_format (col,pattern)

Col is the field to be formatted, pattern is the converted format, and the format refers to the overall format table.

The format of the most commonly used xxxx-xx-xx xx:xx:xx, according to the format table, needs to be written as:

% Y-%m-%d% H:%i:%s, that is:

DATE_FORMAT (xxx,'%Y-%m-%d% HRV% iRV% s')

Convert 2.varchar type to date type

Use the str_to_date function for conversion, using the

Str_to_date (col.pattern), where col is the field or content that needs to be formatted, the format of pattern refers to the format table, and the usage from date to varchar is actually similar.

Attached: format sheet (transfer)

Value

Meaning

Second

% s,% s

Seconds in two-digit form (001.01,..., 59)

Points

% I

Points in two-digit form (001.01,..., 59)

Hour

% H

24-hour system, double-digit hours (0010 01,..., 23)

% h

12-hour system, double-digit hours (0010 01,..., 12)

% k

24-hour system, number of hours (0pm 1,..., 23)

% l

The 12-hour system, the number of hours in the form of hours (0, 1, 12)

% T

24-hour system, time form (HH:mm:ss)

% r

12-hour system, time form (hh:mm:ss AM or PM)

% p

AM morning or PM afternoon

Zhou

% W

The name of each day of the week (Sunday,Monday,..., Saturday)

% a

Abbreviation for the name of each day of the week (Sun,Mon,..., Sat)

% w

Identify the week in digital form (0 week Sunday1 Monday,..., 6=Saturday)

% U

The number indicates the number of weeks, and Sunday is the first day of the week.

% u

The number indicates the number of weeks, and Monday is the first day of the week.

day

% d

Two digits indicate the number of days in the month (01Jing 02,..., 31)

% e

The number represents the number of days in the month (1, 2, 31).

% D

The English suffix denotes the number of days in the month.

% j

The number of days in the middle of the year is represented by three digits (001, 002,..., 366)

Month

% M

English month name (January,February,..., December)

% b

Abbreviated month name (Jan,Feb,..., Dec)

% m

Two digits represent the month (01jue 02,..., 12)

% c

The number indicates the month (1, 2, 12).

Year

% Y

The year represented by four digits (2015, 2015, and 2016.)

% y

The year represented by two digits (15,016.)

Text output

% text

Output text content directly

The above is all the contents of mysql verchar time transfer method, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report