Three database date-to-string comparisons with SQL Server, Oracle, MySQL (V4.11)

Source: Internet
Author: User
Tags getdate

Three database date conversions comparison:
http://blog.csdn.net/zljjava/article/details/17552741

SQL type conversion function: Cast (type1 as Type2)

Date types in the database SQL SERVER

DATE 1970-01-01
DATETIME 1970-01-01 00:00:00

Oracle

DATE 2015-08-07 17:34:37
TIMESTAMP 1970-01-01 00:00:00.000000 is the extended type of date, with fractional seconds

Date-to-string Oracle

To_char (sysdate, ' yyyy-mm-dd ')
Select To_char (sysdate, ' Yyyy-mm-dd hh24:mi:ss ') as nowtime from dual;

SQL Server

CONVERT (varchar, cast (' 1970-01-01 ' as DateTime), 120) 1970-01-01 00:00:00

select convert(char(7),getdate(),20);--2015-10
SELECT CAST( DATEPART(yyyy,getdate()) as CHAR(4)) +  cast( DATEPART(mm,getdate()) as char(2));-- 201510
SelectCONVERT(varchar(100), GETDATE(), 23) --2006-05-16

Http://www.cnblogs.com/zhangq723/archive/2011/02/16/1956152.html

Mysql

Date_format (Sysdate (), '%y-%m-%d ');

String to date Oracle

To_date (sysdate, ' yyyy-mm-dd ')
Select To_timestamp (' 2012-5-13 18:45:34:567 ', ' yyyy-mm-dd hh24:mi:ss:ff9 ') +0 from dual;

Mysql
STR_TO_DATE(sysdate(),‘%Y-%m-%d‘);
Number to string Oracle

(1) using the TO_CHAR function to process numbers
To_char (number, ' format ')
To_char (Salary, ' $99,999.99 ');
(2) using the TO_CHAR function to process the date
To_char (date, ' format ');
To_char (sysdate, ' Q ') season
To_char (sysdate, ' yyyy ') year
To_char (sysdate, ' mm ') month
To_char (sysdate, ' DD ') day
To_char (sysdate, ' d ') Day of the week
To_char (sysdate, ' Day ') days of the week
To_char (sysdate, ' DDD ') the first day of the year

Three database date-to-string comparisons with SQL Server, Oracle, MySQL (V4.11)

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.