sql中CONVERT日期时间格式化
在mysql用来对字符型的时间日期格式化我们常用CONVERT()函数来操作,下面我来给各位朋友详细介绍CONVERT()函数的使用方法,大家可参考。
格式:
CONVERT(data_type,expression[,style])
说明:
此样式一般在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,char,varchar)
相互转换的时候才用到.
例子:
代码如下 | 复制代码 |
SELECT CONVERT(varchar(30),getdate(),101) now |
结果为:
now
|09/15/2001
代码如下 | 复制代码 |
Select CONVERT(varchar(100), GETDATE(), 0) --05 16 2006 10:57AM |
style数字在转换时间时的含义如下:
Style(2位表示年份)
Style(4位表示年份)
输入输出格式
0
100
mon dd yyyy hh:miAM(或PM)
1
101
mm/dd/yyyy
2
102
yyyy-mm-dd
3
103
dd/mm/yyyy
4
104
dd-mm-yyyy
5
105
dd-mm-yyyy
6
106
dd mon yyyy
7
107
mon dd,yyyy
8
108
hh:mm:ss
9
109
mon dd yyyy hh:mi:ss:mmmmAM(或PM)
10
110
mm-dd-yy
11
111
yy/mm/dd
12
112
yymmdd
13
113
dd mon yyyy hh:mi:ss:mmm(24小时制)
14
114
hh:mi:ss:mmm(24小时制)
20
120
yyyy-mm-dd hh:mi:ss(24小时制)
21
121
yyyy-mm-dd hh:mi:ss:mmm(24小时制)
注意了convert与cast的区别了,这里简单说明一下
convert一般用于值,小数之间转换;
cast一般用于小数转数值和字符型

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In Python, we have some built-in time functions such as strftime() and datetime.now() which can be used to find the time in AM/PM format. Time in AM/PM format is used in a variety of applications such as user interfaces, reporting and documentation, data visualization, and event scheduling. When the time is between 11:59:00 midnight and 12 noon, we say AM time. Similarly, we can say that the time between 12 o'clock and 11:59:00 midnight is PM. The abbreviations AM/PM are used to indicate the exact time. Syntax uses the following syntax in the example &miinus;strftime('%I:%M:%S%p')strft

convert is not a software, but a file system modification command in Windows. Convert converts the file allocation table FAT and FAT32 volumes to the NTFS file system while leaving the existing files and folders intact. Its syntax is "convert [Volume] /fs:ntfs [/v] [/cvtarea:FileName] [/nosecurity] [/x]".

PHP is a commonly used programming language used to develop web applications. In the process of developing web applications, it may involve time conversion in different time zones, such as converting American time to Chinese time. This article will detail the steps on how to use PHP to convert American time to Chinese time and provide code examples. 1. Get the US time First, we need to get the US time. The time zone can be set using PHP's built-in function date_default_timezone_set

The convert command is a command line tool in the ImageMagick image processing software package, used for image format conversion, image processing, and image synthesis. Common usage: 1. Simple image format conversion: convert input.jpg output.png; 2. Adjust image size: convert input.jpg -resize 800x600 output.jpg; 3. Image cropping, etc.

How to solve Java time format exception (DateTimeFormatException) Introduction: Java is a widely used programming language, and format exceptions (DateTimeFormatException) are often encountered when processing dates and times. This article will explain how to resolve time formatting exceptions in Java and provide some code examples. 1. What is time formatting exception (DateTimeFormatException) in Java

How to use the TIME_FORMAT function in MySQL to format time into a specific string MySQL is a widely used relational database management system that provides a wealth of functions and operators to process data. In MySQL, there is a very useful function, the TIME_FORMAT function, which can format the time in a specified format and return a string. The basic syntax of the TIME_FORMAT function is as follows: TIME_FORMAT(time,f

The usage is to understand the data type and target data type to be converted, and call the corresponding conversion function to achieve the conversion.

In web development, date and time are very important factors, especially for interaction and data storage. In PHP, the functions for processing dates and times are very powerful, such as getting the current time, converting timestamps into date and time format, comparing two dates and times, and so on. In this article, we will introduce how to handle date and time in PHP. Get the current time In PHP, the function to get the current time is date(). This function takes two parameters, the first parameter is the datetime format and the second parameter is an optional timestamp. by
