Time Date function in PB 2007-05-11 19:42
Date and time functions in SQL Server1. Current system date, timeSelect GETDATE ()2. DateAdd returns a new datetime value on the basis of adding a period of time to the specified dateFor example:
MySQL Query record if there is a timestamp field, the view results inconvenient, can not immediately see the meaning of the timestamp represents, now provides the MySQL format change time function, you can easily see the time after the format.1. The
Numeric Functionsthe commonly used functions for handling numeric values are as follows :
No.
Function name
meaning
1
Digital round ( column | numbers [. ])
Returns the value
Years:YY: two-year 16YYY: three-year 016YYYY: four-year 2016QuarterQ: Return to QuarterMonthMm:MON:MONTH:WeekWw:W:DaysDd:Ddd:Dy:Day:HoursHH:HH24:Score ofMI:SecondsSs:1. Get the current system date-- returns the current system date SELECT from DUAL;2
/*Date_add (Date,interval expr type) and date_sub (Date,interval expr type) perform date operations. Date is a datetime or date value used to specify the start time. Expr is an expression that specifies the time interval value to be added or
Date and Time Functions (1a function that gets the function and time of the current dateCurdate () and current_date () function to get the current dateSelect Current_date (), Curdate (), curdate () +0;Curdate () +0 means converting the current time
CONVERT (varchar (10), field name, conversion format)convert (nvarchar, count_time,121) convert is a date conversion function, typically in the time type (Datetime,smalldatetime) and the string type (Nchar,nvarchar,char , varchar) 3 parameters of
Date functionSysdate-- Current system Time Select from dual;EXTRACT-- get Current year Select Extract (year from from-- years Select Extract ( month from from– month Select Extract (Day from- - DayTo_date--Convert a string to a dateSELECTTo_date (
#now (), gets the date format of the current timestamp [' y-m-d h:i:s '] #sysdate (). Gets the date format of the current timestamp [' y-m-d h:i:s ']select now () select Sysdate (); #curdate () Gets the date format for the current timestamp [' y-m-d
Method 1,Curdate (), Curtime (), now ()Method 2,Utc_date (), Utc_time (), Utc_datetime ();You can see that UTC time is 8 hours smaller than the eight area.AttentionFunctions that return their current date or time are evaluated once at the beginning
getdate () functionReturns the current date and time of the system in the default format of datetimeSyntax format: getdate ()Year () Month () Day () functionReturns the year, month, and date value in Date_expressionSyntax format: year/month/day
The following 4 SQL, which is obviously a 2-class SQL statement. May 19, 2017Question: Walked two times the full table.Select COUNT (*) active merchant number from (select Merchant_code,count (DISTINCT concat (Merchant_code,date (create_date)))
SQL Server Date functionThe following table lists the most important built-in date functions in SQL Server:
function
Description
GETDATE ()
Returns the current date and time
DATEPART ()
The processing of dates in the work is often encountered, the requirements may be varied, so the focus is introduced.1. Get the current dateSelect Now () -- results: 2015-10-28 22:41:11 Select Now (), SLEEP (3), now ()-- results 2015-10-28 22:43:34
SQL Date Data typeSQL Server uses the following data types to store date or date/time values in the database:
DATE-Format YYYY-MM-DD
DATETIME-format: Yyyy-mm-dd HH:MM:SS
smalldatetime-format: Yyyy-mm-dd HH:MM:SS
TIMESTAMP-Format:
GETDATE (): Gets the current date timeDATEADD (datepart, number, date), calculates the date after the increase. The parameter date is the day to be calculated, the parameter number is increment, the parameter datepart is the unit of measurement, and
Write in frontMySQL learning, intermittent, today continue to learn the date of MySQL operation.Series ArticlesMySQL CREATE database, create data tableMySQL's select,insert,delete,updateMySQL group By,order byMySQL's
First, the common date data format1. Get the last digit of the year, two-bit, three-bit, four-bitSelect To_char (sysdate, ' Y ') from dual; --Get the last one of the yearSelect To_char (sysdate, ' YY ') from dual; --Get the last two digits of the
Common Date-type functions1.Sysdate Current date and timeSql> Select sysdate from dual;2.last_day last day of the monthSql> Select Last_day (sysdate) from dual;3.add_months (d,n) Current date d pushes n monthsUsed to increase or decrease some months
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.