SQL determines whether a given date is the year of the Leap years statement--judging by the total number of days in the yearDECLARE @date datetime;Set @date = GETDATE ()Select Case DateDiff (Day,dateadd (Year,datediff (year,0, @date), 0), DateAdd (Year,1+datediff (year,0, @
Label: 1 SELECT DateDiff(YY,'2010-06-1 10:10',GETDATE())--calculate how many years
2 SELECT DateDiff(Q,'2011-01-1 10:10',GETDATE())--Calculate how many quarters 3 months a quarter
3 SELECT DateDiff(MM,'2011-06-1 10:10',GETDATE())--calculate how many months
4 SELECT DateDiff(DD,'2011-06-1 10:10',GETDATE())--calculate how many days
5 SELECT DateDiff(WK,'2011-06-1 10:10',GETDATE())--calculate how many weeks
6
Label:SQL Date-time format conversion SQL datetime format conversion SQL server2000 using convert to get the datetime data type style (full) Processing of date data formats, two examples: CONVERT (varchar (16), time one, 20) results: 2007-02-01 08:02/* time is generally a field in the GETDATE () function or data table
Tags: block floor from Sele amt Concat Digital STR EndBecause the project needs to get (the sum of occurrences in this quarter)/(number of days in the quarter) data (plus monthly average, average annual data). Judging the time of the season is a difficult point, the beginning of the time to write a bunch of cases when to judge the month, and then write the discovery, it is too stupid. So I began to think of ways. Suddenly brainwave, a quarter is 3 months
, getdate), 0)
13. Last day of the yearSelect dateadd (MS,-3, dateadd (YY, datediff (YY, 0, getdate () + 1, 0 )).
Date and time functions in SQL Server1. Current System Date and TimeSelect getdate ()
2. dateadd returns a new datetime value based on a period of time added to the specified date.For example, add
DATEADD Date FunctionThe DATEADD () function adds or subtracts a specified time interval from a date.Day:Add two days to the current dateSelect DATEADD (Day,2,'2014-12-30')- on Select DATEADD (DD,2,'2014-12-30'Month:Add two months to the current dateSelect DATEADD(MM,2,'2014-12-30'Results -- Geneva- - Select DATEADD(MONTH,2,'2014-12-30'Results -- Geneva- - Years:Add two years to the current dateSelect DATE
spaces)-130* Kuwait DD Mon yyyy Hh:mi:ss:mmmAM-131* Kuwait Dd/mm/yy Hh:mi:ss:mmmAMAbout the format conversion of fields in Emaker and the operation code between fields can be added to the attribute "format conversion (read out)" and "format conversion (write)", the "field" position in the table field settings can also be flexible add function. For example: ' AF ' +id or id+ '/' +pwd, convert (varchar (), F1),Convert (int,%)-19110000 (read out)Convert
() function of php () functions are much more efficient, but we cannot ignore the execution overhead of mysql databases. Therefore, FROM_UNIXTIME () is fast without considering the database overhead.
PHP source code reference:
The Code is as follows:
Copy code
Header ("Content-type: text/html; charset = UTF-8 ");// Program running time$ Starttime = explode ('', microtime ());/* · The following code area ·········*/$ Link = mysql_connect ("localhost", "root", "root ");M
system time -the type that needs to be changed , the quantity that needs to be changed, the time and date to changeSelect DATEADD (hh,5, ' 2015-12-12 ')--datediff Calculate the time difference, different different, difference--the type that needs to be changed, the start date, the end time dateSelect DateDiff (MM, ' 2013-12-31 ', ' 2014-1-3 ')DECLARE @startday varchar--you need to
ConvertExplicitly converts a data type expression to another data type. Because some requirements often use different date formats, the following can be found inFormat the date in SQL Server.
SQL Server supports the data format in the Arabic style using the Kuwait algorithm.
In the table, the two columns on the left re
table [table name] Add field name the datetime default function increases the date Type field, where the function can be now (), date (), and so on, representing the default value (which is most commonly used, and other properties, which can be referenced by the following data type Delete field: ALTER TABLE [table name] Drop field name Modify size of variable-
, dateadd (mm, datediff (mm, 0, getdate (), 0 ))
7. Last day of last yearSelect dateadd (MS,-3, dateadd (YY, datediff (YY, 0, getdate (), 0 ))
8. Last day of the monthSelect dateadd (MS,-3, dateadd (mm, datediff (M, 0, getdate () + 1, 0 ))
9. The last day of the yearSelect dateadd (MS,-3, dateadd (YY, datediff (YY, 0, getdate () + 1, 0 ))
10. the first Monday of this monthSelect dateadd (wk, datediff (wk, 0, dateadd (DD, 6-datepart (day, getdate (), getdate (), 0)
Returns the current
Use convert in SQL server2000 to get the datetime data type style (full)Processing of date data formats, two examples:CONVERT (varchar (16), time one, 20) results: 2007-02-01 08:02/* time is generally a field in the GETDATE () function or data table */CONVERT (varchar (10), time one, 23) Result: 2007-02-01/*varchar (10) represents the format of the date output, w
Use convert in SQL server2000 to get the datetime data type style (full)Processing of date data formats, two examples:CONVERT (varchar (16), time one, 20) results: 2007-02-01 08:02/* time is generally a field in the GETDATE () function or data table */CONVERT (varchar (10), time one, 23) Result: 2007-02-01/*varchar (10) represents the format of the date output, w
Label:Use convert in SQL server2000 to get the datetime data type style (full) Processing of date data formats, two examples: CONVERT (varchar (16), time one, 20) results: 2007-02-01 08:02/* time is generally a field in the GETDATE () function or data table */ CONVERT (varchar (10), time one, 23) Result: 2007-02-01/*varchar (10) represents the format of the date
DateTime is used in C. toString (yyyy-MM-dd), DateTime. toString (MMddyyyy), a date-to-String Conversion method, is useless in SQLserver, and thus a FUNCTION is written. dateTime in. net. the ToString (formatprovide) method is similar, but only the date part is implemented.
DateTime is used in C. toString ("yyyy-MM-dd"), DateTime. toString ("MM/dd/yyyy"), a date-
The job needs to query the data of this month and this month for ranking. Take a closer look at the date format stored in the database, which is, in this way, I thought that the query method of the database by second would not work. I found a date addition and subtraction SQL function datediff (now, oldtime) on the Internet ). After testing, I can use the followi
This section briefly describes five data types in SQL: numeric, text, numeric, logical, and date.
Character Type
Varchar and char
The differences between varchar and char data are subtle, but important. They are used to store strings of less than 255 characters.
Assume that you enter the data Bill Gates in a 40-character varchar field. When you extract this data from this field, the length of the data you e
Label:Use convert in SQL server2000 to get the datetime data type style (full) Processing of date data formats, two examples: CONVERT (varchar (16), time one, 20) results: 2007-02-01 08:02/* time is generally a field in the GETDATE () function or data table */ CONVERT (varchar (10), time one, 23) Result: 2007-02-01/*varchar (10) represents the format of the date
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.