ASP time addition and subtraction and conversion
A = 2:23:15
B = 2:23:15
Question 1
How to convert a to date format not character format!
Question 2
How to convert a to 2007 date format not character format!
Question 3
How to convert a to 2:23:15 date format not character format!
Question 4
Why is a-B correct! Why not it's time? How to make the result time
AnswerQuestion 1:Formatdatetime (A, 2)Question 2:Year ()Question 3:Formatdatetime (A, 4)Question 4:
', ' two ', ' three ', ' four ', ' five ', ' six ']; switch (interval) {case ' Y ':p artstr = Mydate.getfullyear (); Case ' m ':p artstr = Mydate.getmonth () +1;break; Case ' d ':p artstr = Mydate.getdate (); Case ' W ':p artstr = Week[mydate.getday ()];break; Case ' ww ':p artstr = Mydate.weeknumofyear (); Case ' h ':p artstr = mydate.gethours (); Case ' n ':p artstr = Mydate.getminutes (); Case ' s ':p artstr = Mydate.getseconds (); return partstr; } //+---------------------------------------
Server Date functionDefinition and usageThe DATEDIFF () function returns the number of days between two dates.GrammarDATEDIFF (datepart,startdate,enddate)The startdate and enddate parameters are valid date expressions.The datepart parameter can be the following value:
DatePart
Abbreviations
Years
YY, yyyy
Quarter
QQ, Q
Month
MM, M
The day of the year
D
Definition and usageThe DATEDIFF () function returns the number of days between two dates.GrammarDATEDIFF (Datepart,startdate,enddate)The datepart parameter can be the following value:DatePart abbreviation year yy, yyyy quarter QQ, Q month mm, M-year of the day dy, y dd, D week wk, WW week DW, W hour hh minutes mi, N sec SS, s Ms ms Subtle MCS nanosecond NS
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:
Address: http://www.wlm.so/Article/Detail/lmb49q5hxpqyi00000
I just searched for datediff in C # on Baidu. I was shocked to see that C # didn't have this function.
There are also various user-defined functions.In desperation, write a datetime variable by yourself. Look at it, yo, there are adddays or something. This is not an issue.C # There are such perfect adddays, addmonths and other functions. What else do I need dateadd or something.After testi
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 = date. parse (date1.replace (/-/g, '/'); var dt2 = date. parse (date2.replace (/-/g, '/'); try
": $ 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 * (**************/ function
In PHP project development, it is often used to automatically determine the expiration time of some records. There is an automatic update time timestamp Field in the existing database. The value of another field is updated for more than 7 days based on the comparison between this time and the current system time. You can directly use the following SQL statement:
Update testtable set status = 2 where datediff (now (), testtime)> 7 and status;
Recently, there is a function that needs to query data in the database for a certain day, and the data time is in the timestamp format. In this way, when I query data, there are two options:
Select * From tuples where datediff (created_on, '2017-07-09 ') = 0Select * From tuples where date_format (created_on, '% Y-% m-% D') = '2017-07-09'
The amount of data in the database is large, with more than 4 million entries. Compare the execution time
Sh
The date and time functions in SQL Server are always problematic in this regard. So, I will summarize what I mainly useDatepart(Month, getdate (). This item can be set to day (now () in access. Unfortunately, the day () in SQL Server does not support parameters.Date and time functions in SQL Server
These scalar functions operate on the input values of date and time, and return a string, numeric value, or Date and Time Value.
The following table lists Date and Time Functions and Their determinist
DateDiff (Timeinterval,date1,date2 [, FirstDayOfWeek [, FirstWeekOfYear]])
TimeInterval represents the type of time separated by the following code:
YYYY years
Q season
M month
Y number of days in a year
D-Day
W Number of days in a week
WW Week
H time
N Minutes
s seconds
Specific examples:
Copy Code code as follows:
D1=datediff ("D", now (), CDate (RS ("adddate"))//Read the date of the item added
Oh, the following code is a little messy ah, is what I do in the test, PHP mysql date calculation code [DATEDIFF] is also I need today to try it. Look at the code here.
function A ($d) {$Date _1=date ("y-m-d");$Date _2= $d;
$Date _list_a1=explode ("-", $Date _1);$Date _list_a2=explode ("-", $Date _2);
$d 1=mktime (0,0,0, $Date _list_a1[1], $Date _list_a1[2], $Date _list_a1[0]);
$d 2=mktime (0,0,0, $Date _list_a2[1], $Date _list_a2[2], $Date _list_
, $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
(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)
// 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, date (m), date (d), date (Y )); /***** simulate the dateadd function in sqlserver ******* $ part Type: string value range: y EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Date. inc. php3: two functions used to simulate SQLSERVER: dateadd (), datediff () _ PHP _ China Network M
)-math.floor (t/1000);
return I[interval];
}
DateAdd Method
Returns the Date object for which the specified time interval has been added.
Dateobj.dateadd (interval, number)
Parameters
Dateobj
Required option. Any Date object.
Interval
Required option. A string expression that represents the time interval to add. For numeric values, see the "Settings" section.
Number
Required option. Numeric expression that represents the number of time intervals to add. Numeric expressions can be positive
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.