-- Parameter:Datepart varchar2 -- year comparison? Month? ?Startdate varchar2 -- start dateEndDate Varchar2 -- end date-- Oracle9i passed the test*/
Create Or Replace Function Datediff(Datepart In Varchar2,StartDate In Varchar2,EndDate In Varchar2) Return Number IsReallyDo Numeric;BeginSelect Case Upper (Datepart)When 'yyyy' ThenTrunc (Extract (Year From CDate (EndDate ))-Extract (Year From CDate (StartDate )))When 'M' ThenDatediff ('yyyy', StartDate,
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
Datediff (timeinterval, date1, date2 [, firstdayofweek [, firstweekofyear])
// Timeinterval indicates the time interval type, CodeIs:
Yyyy
Q quarter
M month
Y number of days in a year
D
Number of days per week
WW week
H hour
N minutes
S seconds
Example: The Code is as follows:
D1 = datediff ("D", now (), cdate (RS ("adddate") // read the date added to the item from the database
If D1>-15 then
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 the first day of the week. If not specified, th
, $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 DateDiff ($part, $date 1, $date 2) {
$diff = $date 2-$date 1;
$year 1=date ("Y"
= mktime ($ hour, $ min, $ sec, $ month, $ day, $ year );Return $ ret;}/***** Simulate the datediff function in sqlserver *******$ Part type: stringValue Range: year, month, day, hour, min, secIndicates the part of the date to be added.$ Date1, $ date2 type: timestampTwo dates to be comparedReturn type: Numeric Value* ************** End *(*************/Function datediff ($ part, $ date1, $ date2 ){// $ Dif
}
$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 * (*************/
function DateDiff ($part, $date 1, $date 2) {
$diff = $date 2-$date
--getdate Current system date, timeSelect getdate()--2014-11-24 13:22:40.407--the CONVERT () function can display date/time data in different formatsSelect Convert(varchar( -),getdate(), at)--2014-11-24--DateDiff Returns the number of date and time boundaries across two specified datesSelect DateDiff( Day,'2014-11-24','2014-12-28')-- theSelect DateDiff(Month,'201
(calendar.month) +calendar.get (calendar.year) *12;//month = year of the current year *12 + month of the current year, same as - Calendar.settime (endDate); - intEndmonth = Calendar.get (calendar.month) +calendar.get (calendar.year) *12; - returnEndmonth-Startmonth; - } in /*find the number of days between StartDate and EndDate*/ - if("D". Equalsignorecase (datetype) | | "DD". Equalsignorecase (Datetype)) { to LongStartTime =startdate.gettime (); + LongEndTime =enddate.gettime (); - return(int)
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.getdate () +7*number));
Case "H": Return new Date (Date.sethours (date.gethours () +number)
Town Field Poem:——— Dream who feel, the water month Build blog. Baiqian tribulation, only know the vicissitudes of the world.——— today holds the Buddhist language, the technology is boundless willing to learn. Willing to do what you learn, cast a conscience blog.——————————————————————————————————————————1 Code1 --View the current time for easy comparison2 Select getdate()3 Select DateDiff( Year,'1996-11-01',getdate())4 Select
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 DateDiff (), this function can return a time difference of seconds, That means we put in
, $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 DateDiff ($part, $date 1, $date 2) {
$diff = $date 2-$date 1;
$year 1=date ("Y", $date
Requirement: Splits a string that uses a delimiter connection for a fixed number of digits, such as splitting a record 215|482|850|870 into 215,482,850,870 four recordsResult: The WITH RECURSIVE statement is capable of implementing this function and
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.