Discover datediff function in sql, include the articles, news, trends, analysis and practical advice about datediff function in sql on alibabacloud.com
DateAdd function:
Copy Code code as follows:
function DateAdd (interval,number,date) {
Switch (Interval.tolowercase ()) {
Case "Y": Return new Date (Date.setfullyear (Date.getfullyear () +number));
Case "M": Return new Date (Date.setmonth (Date.getmonth () +number));
Case "D": Return new Date (Date.setdate (Date.getdate () +number));
Case "W": Return new Date (Date.setdate (Date.get
}
$ret =mktime ($hour, $min, $sec, $month, $day, $year);
return $ret;
}
/**** simulate the DATEDIFF function in SQL Server *******
$part Type: string
Value range: year,month,day,hour,min,sec
Which part of the date to increase
$date 1, $date 2 type: Timestamp
Indicates: two dates to compare
Return type: Numeric value
End * (*************/
What I'm going to introduce today is a function that converts time (for example: 2008-8-8 13:45:22) into seconds in ASP, and the opposite of converting seconds to time. Of course when the time is converted. Must have a relatively fixed time, that is GMT. Think about it. Because Greenwich Mean Time is "January 1, 1970 00:00:00" Start, ASP provides a function called DateD
, $sec, $month, $day, $year);
return $ret;
}
/**** simulation of DATEDIFF functions in SQL Server *******
$part Type: string
Value range: year,month,day,hour,min,sec
Indicates: Which part of the date to increase
$date 1, $date 2 type: Timestamp
Represents: two dates to compare
return type: Numeric
End * (*************/
function
How to Use the datediff function in VB
Datediff (interval, date1, date2 [, firstweekofyear [, firstweekofyear])Returns the value of variant (long), indicating the number of time intervals between two specified days.Interval: Set the unit of Period Calculation between two dates. For example,>Interval= "M" indicates that the calculation unit is month. >IntervalSu
startdate from enddate.
To avoid uncertainty, use a four-digit year. For information about the two-digit year, see the two digit year cutoff option.
Enddate
See startdate.
1. Return two-quarter time difference records
CodeAs follows: if necessary, you can change the time field to the corresponding field in the database.
View code
1
Declare @ startdatetime
2
Declare @ enddatetime
3
Set
@ Startdatetime
=
'
2011-01-01
DateDiff is commonly used to calculate date difference functions, using the following syntax:DATEDIFF (DatePart, StartDate, EndDate)Where parameter datepart has the following options (only common parameters are listed):
DatePart
Abbreviation
Explain
Year
Yy,yyyy
Years
Month
Mm,m
Month
Day
Dd,d
Days
Week
Wk,w
Week
How to use DateDiff function in VB DateDiff (interval, Date1, date2[,firstweekofyear[,firstweekofyear])Returns a Variant (long) that represents the number of time intervals between two specified datesinterval: Sets the unit of the period calculation between two dates.For example, >interval= "m" means the calculated unit is month. >interval setting values such as:
VB has many built-in functions are very practical, very good, this article on the DateDiff to introduce!
1, function functions:
Returns the time interval between two dates.
Example:
DateDiff("D", now, thedate)
D stands for Day (day) now is the current time, Thedate is a time we define ourselves
The result of the entire f
Label:1. First day of last monthSELECT CONVERT (CHAR), DATEADD (Month,-1,dateadd (Dd,-day (GETDATE ()) +1,getdate ()), 111)2. Last day of last monthSELECT CONVERT (CHAR), DATEADD (Ms,-3,dateadd (mm, DATEDIFF (Mm,0,getdate ()), 0)), 111) + ' 23:59:59 '3, the first day of the monthSELECT CONVERT (CHAR), DATEADD (Dd,-day (GETDATE ()) +1,getdate ()), 111)4, the last day of this monthSELECT CONVERT (CHAR), DATEADD (Ms,-3,dateadd (Mm,
Today, in the work of a problem, statistics this week, the use of the DateDiff function due to the confusion of W and week produce statistical results errorThe setting values for the parameter interval are as follows:
Value
Abbreviation (SQL Server)
Description
Year
Yy
Year 1753 ~ 9999
Quarter
Qq
How to Use the datediff function in VB Datediff (interval, date1, date2 [, firstweekofyear [, firstweekofyear])Returns the value of variant (long), indicating the number of time intervals between two specified days.Interval: Set the unit of Period Calculation between two dates. For example,>Interval= "M" indicates that the calculation unit is month. >IntervalS
SELECT DATEDIFF (year, ' 1986-09-01 ', ' 2016-02-01 ') as Diffdate
DatePart
Abbreviations
Years
YY, yyyy
Quarter
QQ, Q
Month
MM, M
The day of the year
Dy, y
Day
DD, D
Week
WK, WW
Week
DW, W
Hours
hh
Minutes
MI, n
Seconds
SS, S
The datediff function returns the interval between two dates. Format:
Datediff (interval, date1, date2 [, firstdayofweek [, firstweekofyear])
ParametersIntervalRequired. String expression indicates the time interval between date1 and date2. Date1, date2Required. Date expression. Two dates used for calculation.FirstdayofweekOptional. Specify the constant of th
, $sec, $month, $day, $year);
return $ret;
}
/**** simulate the DATEDIFF function in SQL Server *******
$part Type: string
Value range: year,month,day,hour,min,sec
Which part of the date to increase
$date 1, $date 2 type: Timestamp
Indicates: two dates to compare
Return type: Numeric value
End * (*************/
function
The date processing function of JavaScript is not rich in VBScript functions and is always uncomfortable. Because of the time difference, I wrote one myself and used it together.
Function datediff (interval, date1, date2) {var objinterval = {'D': 1000*60*60*24, 'H': 1000*60*60, 'M ': 1000*60,'s ': 1000, 't': 1}; interval = interval. touppercase (); var dt1 = dat
": $ min + = $ N; break; case "Sec": $ sec + = $ N; break; default: return $ ret; break; } return $ ret; }
/***** simulate the datediff function in sqlserver ******* $ part type: String value range: year, month, day, hour, Min, SEC indicates the part of the date to be added. $ date1, $ date2 type: Timestamp indicates: two dates to be compared return type: value **************** end * (*******
The custom DateDiff function in JavaScript is compatible with all browsers. DateDiff is used to return the time interval between two dates.
The Code is as follows:
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.