Business Background: for example, data center management. You can set a special period of time for each day. You can set a discount between and, and a discount between and, off from PM to PM,
Since my business is not cross-day, it must be clear.
DateDiff function
Returns a Variant (long) that represents the number of time intervals between two specified dates.
Grammar
DateDiff (interval, date1, date2[, firstdayofweek[, FirstWeekOfYear])
The following named arguments are in the
---restore content starts---All data for Today: SELECT * FROM table name where DateDiff (dd,datetime Type field, GETDATE ()) =0All data yesterday: SELECT * from table name where DateDiff (dd,datetime Type field, GETDATE ()) =1All data within 7 days:
Records reprinted from: Http://www.cnblogs.com/suruozhong/p/5974595.htmlall data for today: SELECT * FROM table name where DateDiff (dd,datetime Type field, GETDATE ()) =0 all data for yesterday: SELECT * from table name where DateDiff (DD, DateTime
One, Time functionWhen you use stored procedures, SQL functions, you encounter some processing of time. such as the acquisition of time and the addition and subtraction. In this case, the SQL comes with the time function. Below I list these
All data for Today: SELECT * FROM table name where DateDiff (dd,datetime Type field, GETDATE ()) =0All data yesterday: SELECT * from table name where DateDiff (dd,datetime Type field, GETDATE ()) =1All data within 7 days: SELECT * from table name
The date () function gets the dates,
The time () function gets the times.The now () function can get the current date plus time.
Now () gets the current system date and time, the ASP output can be written like this: Years (now ()) Gets the year, ASP
A1, select Update_date, convert (varchar (), update_date,111) JJ, CONVERT (varchar (), update_date,8) AA from Report_ Month//update_date is a datetime type and results are shown as:Update_date JJ AA2007-01-06 16:14:50.437 2007/01/06 16:14:50Select
Read Catalogue
Get Current Month Day
Ways to get a variety of dates
function parameters/Functions
Back to TopGet current Month daySelect MONTH (GETDATE ()) 6 Year () gets yearsDay () Get dateSelect Day
Date function
Description: returns the current system date.
Syntax: Date
Dateadd FunctionDescription: return the date of the specified interval that has been added.Syntax: dateadd (interval, number, date)Interval: required. String expression,
Copy codeThe Code is as follows: public static string DateDiff (DateTime DateTime1, DateTime DateTime2)
{
String dateDiff = null;
Int date = 0;
Try
{
Int year = Convert. ToInt32 (DateTime2.ToString ("yyyy")-Convert. ToInt32 (DateTime1.ToString
Note: copy a table (only copy structure, source table name: a new table name: B)Select * into B from a where 1 <> 1
Description: copy a table (copy data, source table name: a target table name: B)Insert into B (a, B, c) select d, e, f from B;
Calculating the time difference in PHP is sometimes a hassle! But as long as you've mastered the use of datetime functions, that's a simple thing to do.
Recently in the study of their love scarf to calculate the number of days of love, which
The first day of a monthSQLScript:
Select dateadd (mm, datediff (mm, 0, getdate (), 0)
Monday of this week
Select dateadd (wk, datediff (wk, 0, getdate (), 0)
The first day of a year
Select dateadd (YY, datediff (YY, 0, getdate (), 0)
Date function
Description: Returns the current system date.
Syntax: Date
DATEADD function
Description: Returns the date when the specified time interval has been added.
Syntax: DateAdd (interval, number, date)
Interval: Must choose. A string
Description: Copy table (copy only structure, source table name: A new table name: b)SELECT * into B from a where 1<>1
Description: Copy table (copy data, source table name: A target table name: b)Insert into B (A, B, c) select d,e,f from B;
Date functionDescription: Returns the current system date.Syntax: Date
DATEADD functionDescription: Returns the date when the specified time interval has been added.Syntax: DateAdd (interval, number, date)Interval: Must choose. A string expression
Function
/*
Every function has only one sentence!
In fact, from another blog I dug out:
T-SQL generates two new true Gregorian calendars
Http://blog.csdn.net/playyuer/archive/2004/04/07/2860.aspx
T-SQL generates a simple Gregorian calendar T-SQL
1. The first day of one monthsSELECT DATEADD (mm, DATEDIFF (Mm,0,getdate ()), 0)
2. Monday of this weekSELECT DATEADD (wk, DATEDIFF (Wk,0,getdate ()), 0)
3. The first day of the yearSELECT DATEADD (yy, DATEDIFF (Yy,0,getdate ()), 0)
4. First day of
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.