SQL statement used to determine whether a given date is in a leap year -- declare @ datedatetime based on the total number of days of the year; set @ dategetdate () selectcasedatediff (day, dateadd (year, datediff (year, 0, @ date), 0), dateadd (year, 1 + datediff (year, 0, @ date), 0) nbsp
Label:Date-time functions 1. Get the current date getdate The GETDATE () function returns the date and time of the computer on which the current SQL Server servers are located, in the format of the datetime data type. Its syntax format is GETDATE (). The return value is rounded to the nearest fractional fraction of the second, with a precision of. 333 seconds th
Sometimes we have to count the data of the date specified in the database, such as the usual, today, yesterday, tomorrow, this week, last week, this month, the last month's data, as well as the date of the addition and subtraction, except we can use Strtotime to calculate also can refer to the following method. SQL min
Function parameters/functionsGetDate () returns the current date and time of the system.DateDiff (interval, date1, date2) returns the difference date2-date1 between date2 and date1 in the way specified by intervalDateAdd (interval, number, date) in the format specified by interval, plus the date after the numberDatePart (interval,
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
1, the common date method (below getdate () = ' 2006-11-08 13:37:56.233 ')(1) Datename (DatePart, date)Returns a String that represents the specified date portion of the specified date. DatePart See the list below.Select Datename (DayGetdate-- return 8(2) DATEPART (DatePart, date
1, the common date method (below getdate () = ' 2006-11-08 13:37:56.233 ')(1) datename (datepart, date)Returns a String that represents the specified date portion of the specified date. DatePart See the list below.SELECT Datename (Day,getdate ()) – returns 8(2) DATEPART (DATEPART,
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 add a data type when decl
SQL queries by a value of the date.
-- Take 12:56:55 as an Example-- Convert (nvarchar (10), CreateDate, 120) => 2013-12-10-- DATEPART (month, CreateDate) => 12-- DATEPART (year, CreateDate) = gt; 2013
-- This is also possible-- YearSelect datepart (YEAR, '2017-06-08 ')Select datepart (yyyy, '2017-06-08 ')Select datepart (yy, '2017-06-08 ')-- MonthSelect datepar
, see the following blog:Http://www.jb51.net/article/33330.htmNow, I am using this knowledge to solve my problem. The first is to count the reported volume by day, accurate to the daily time limit: CONVERT (varchar (11), ReportTime, 20) that is, yyyy-mm-ddThen the group by problem is solved. The SQL code is:Copy codeThe Code is as follows:Select ReportPerson, CONVERT (varchar (11), ReportTime, 20) as 'reportime', count (*) as reportTotal from PCR_Cons
examples, see the following blog:Http://www.jb51.net/article/33330.htm
Now, I am using this knowledge to solve my problem. The first is to count the reported volume by day, accurate to the daily time limit: CONVERT (varchar (11), ReportTime, 20) that is, yyyy-mm-ddThen the group by problem is solved. The SQL code is:Copy codeThe Code is as follows: select ReportPerson, CONVERT (varchar (11), ReportTime, 20) as 'reportime', count (*) as reportTotal fr
The SQL statement in mysql increases the date by one year.
Some fields in the mysql table display dates. Due to various needs, it needs to be adjusted one year later.
The statement for updating the statement added by one year on the mysql date is as follows:
UPDATE table SET date = DATE_ADD(
,-1, GETDATE ()),111)//111 is the style number, (100-114)Query first day of the month Date: Select DATEADD (mm, DATEDIFF (mm,0, GETDATE ()),0) asfirstday Query Last day of the month Date: Select DateAdd (MS,-3, DATEADD (mm, DATEDIFF (M,0, GETDATE ()) +1,0)) asLastday//change-The value of 3 changes accordinglyHow many d
// It is inconvenient to process dates in PHP, for example, to find the month with a different date? What should I do? // File name: date. inc. php3 // before using these two functions, convert the date or date to the timestamp type. // For example: // $ todaymktime (0, 0, 0
SQL query of date fields
// Query all the data generated at every daySelect * from table where datepart (HH, Date Field) = 8// Query all records whose dates are 2006-7-6Select *From cstrecordWhere (datepart ([Day], optime) = 6) and (datepart ([year], optime) = 2006) and(Datepart ([month], optime) = 7)1) Remove
Transferred from: http://www.cnblogs.com/zhangq723/archive/2011/02/16/1956152.htmlOne, SQL Server date-time functionsDate and time functions in SQL Server1. Current system date, timeSelect GETDATE ()2. DateAdd returns a new datetime value based on adding a period of time to the specified dateExample: Add 2 days to the
The database tutorial design must note that the Time field is int (11) so that the database is stored in a digital date-time stamp, we can use the Mktime function to find the current date of the timestamp to add and subtract on OK, see the example below
One month
Copy Code code as follows:
$lastMonth = mktime (
Tags: composition highlight char Data time interception Introduction Group SeleIn this article, the date GetDate () is made up of two parts, namely today's date and time of day: Select GetDate ()With Datename () you can get the corresponding year, month, day, and then connect them together: Select Datename (Year,getdate ()) + '-' +datename(
Function
Use Northwind
Go
CREATE FUNCTION Getstar (@ datetime)
RETURNS varchar (100)
As
BEGIN
--just one sentence of SQL
Return
(
--declare @ datetime
--set @ = getdate ()
Select Max (Star)
From
(
--the constellation, the starting date of the constellation, the day of the constellation start
Select ' Capricorn ' as star,1 as [month],1 as [day]
UNION ALL select '
The job needs to query the data of this month and this month for ranking. Take a closer look at the date format saved in the database as 2010-02-2314: 2: 3, in this way, I thought that the query method of the database by second would not work. I found a date addition and subtraction
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