Php time comparison function, returns the difference of several seconds, minutes, hours, or days between two dates
Function DateDiff ($ date1, $ date2, $ unit = "") {// Time comparison function, returns the seconds, minutes, hours, or days of difference between two dates
Switch ($ unit ){
Case's ':
$ Pidend = 1;
Break;
Case 'I ':
$ Pidend = 60; // oSPHP. COM
The SQL statement is used to calculate the number of working days between two dates.
/*Due to a strange demand at work, the SQL language is used to calculate the number of working days between two days.It is set to have 5 working days in a week, from Monday to Friday.Note:Number of working days in the first week: DATEPART (dw, @ begdt)-DATEPART (dw, @ begdt), minimum 0 daysNumber of working days in the last week: DATEPART (dw, @ enddt), up to 5 daysCa
Newtonsoft.Json.dll provides a very good way to serialize and deserialize Json, but the processing of dates has been a long struggle for me. First define the class as follows: Public class student{ publicint id{get; Set;} Public string name{get; Set;} Public DateTime birthday{get; Set;}}The serialization code is as follows:New Student () { 1, "zhangsan", = = Newtonsoft.Json.JsonConvert.SerializeObject (stu); Console.WriteLine
calculation sample code:
/*** Time addition/subtraction processing ** $ strDate: Time string to be processed * $ days: plus or minus days **/public function ChangeDate ($ strDate, $ days) {$ time = time (); if (isset ($ strDate )! Empty ($ strDate) {$ time = strtotime ($ strDate);} return date ('Y-m-d H: I: s ', strtotime ("$ days day", $ time ));}
Sample Code for obtaining the start and end dates of the current week and month:
/*** Get the start an
Django Ubuntu: Database returned an invalid value in QuerySet. dates (). Solution to the error
This error occurs when running the Django project created in Windows! Database returned an invalid value in QuerySet. dates (). Are time zone definitions and pytz installed?
Install pytz as prompted
1. Install easy_install first:
sudo apt-get install python-setuptools
2. Go to the official website to get the fi
Formatted dateThe first parameter of the date () function specifies how the date/time is formatted. It uses letters to represent the format of dates and times. Here is a list of some availableThe letters:D-Day of the month (01-31)• M-Current month, in Digital (01-12)Y-Current year (four digits)You can find all the letters you can use in the format parameters in our PHP Date reference manual.You can insert additional characters between letters, such as
C # obtain the first day of the current month and the last day to calculate the number of days between the two dates,
Obtain the first and last days of the current month.
DateTime now = DateTime. Now; DateTime firstDay = new DateTime (now. Year, now. Month, 1); DateTime lastDay = firstDay. AddMonths (1). AddDays (-1 );
Calculate the number of days between two dates
DateTime start = firstDay; DateTime en
Returns the maximum number of consecutive days in a set of dates sorted from small to large.Specific Method:
static short Days() { var days = new List
Console output: Console. WriteLine (Days ());
// Output result:
// Algorithm principle:
// Compare the first element with the second element. if the date is different, the first element jumps out of the loop and continues the comparison from the next element.// Compare the first elemen
datestring_01= "2016-01-01 11:11:11"; String datestring_02= "2016-01-02 11:11:11";Try{Date date_01=Sdf.parse (datestring_01); Date date_02=Sdf.parse (datestring_02); System.out.println (Date_01.before (date_02)); //true when date_01 is less than date_02, true, otherwise falseSystem.out.println (Date_02.after (date_01));//true, True if date_02 is greater than date_01, otherwise falseSystem.out.println (Date_01.compareto (date_02));//-1, when date_01 is less than date_02, 1System.out.println (Dat
Recently do the system often need to use JS about time, I am not very familiar with JS to write a variety of time, date code, are online Baidu, basic can see understand, but they are not written out, so the use of JS should be in the blog record, deepen the impression./** * Ask for two days difference between dates * @param startdatestr * @param enddatestr * @returns */function getDays (startdatestr, enddatestr) {var sep Aratorstr = "-"; var startdate
SQL query special data that does not include date SQL quot; select * fromtestwheredatesnotin (#2010-05-03 #, #2010-05-12 #) quot; the date format must be prefixed with # so that we can find all the data that does not include #2010-05-03 #, #2010-05-12 #. Then, let's look at the stupid method 2 SQL quot; sele SQL queries special data that does not include dates
SQL = "select * from test where dates
You must have encountered such a situation that there are two date objects, and then you need to determine whether they are equal. The following method is used to determine:
The Code is as follows:
Var date1 = new Date ("2013-11-29 ");Var date2 = new Date ("2013-11-29 ");Console. log (date1 = date2); // false
Here, date1 and date2 look the same, but running date1 = date2 returns false. This is because date1 and date2 are all objects and their types are reference types. Therefore, if you ne
This article mainly introduces how many weeks php calculates in a year, and obtains the start and end dates of each week. If you need them, refer to them.
This article mainly introduces how many weeks php calculates in a year, and obtains the start and end dates of each week. If you need them, refer to them.
Recently, I took over a project. One of the requirements was to use php to obtain the weeks o
This article mainly introduces how to use php to calculate the difference function of two dates. It is very practical and recommended to friends in need. Very simple and practical functions to share with you,
Code:
The Code is as follows:
/*** Date-calculate the difference between two dates* @ Return int*/Public function get_difference ($ date, $ new_date ){$ Date = strtotime ($ date );$ New_date =
:yyyymmddhhmmssffff}", DT);Calculates the difference in the number of days between 2 dates-----------------------------------------------DateTime dt1 = Convert.datetime ("2007-8-1");DateTime DT2 = Convert.datetime ("2007-8-15");TimeSpan span = dt2. Subtract (DT1);int Daydiff = span. Days + 1;Calculate the number of days of the month in a year-----------------------------------------------int days = Datetime.daysinmonth (2007, 8);days = 31;Add one day
to create custom patterns, and the standard format characters listed in the first table cannot be used to create custom patterns.The custom pattern is at least two characters long;1. DateTime.ToString ("D"); Returns a DateTime value; "D" is a standard short date pattern.2. DateTime.ToString ("%d"); Returns the day of the month; "%d" is a custom pattern.3. DateTime.ToString ("D"); Returns the day of the month followed by a blank character, and "D" is a custom pattern.Three, C # common date proce
);//2005-11-5 14:23:23string. Format ("{0:YYYYMMDDHHMMSSFFFF}", DT); Calculates the difference in the number of days between 2 dates-----------------------------------------------DateTime dt1= Convert.datetime ("2007-8-1");D atetime DT2= Convert.datetime ("2007-8-15"); TimeSpan span=DT2. Subtract (DT1);intDaydiff = span. Days +1; Calculates the number of days of a month in a year-----------------------------------------------intDays = Datetime.daysinm
1 //Write a program that calculates the number of days between two dates in Java. 2 3 ImportJava.util.regex.Matcher;4 ImportJava.util.regex.Pattern;5 6 Public classDemo4 {7 Public Static voidMain (string[] args) {8 Try {9SYSTEM.OUT.PRINTLN (Difference of days ("2016-11-30", "2016-5-31")));Ten}Catch(Exception e) { One e.printstacktrace (); A } - } - the Private StaticPattern p = pattern.compile ("(\\d{4})-(\\d{1,2})
: The sometime is stored 1:50. Please refer to Firstweekday and Minimumdaysinfirstweek for other instructions.-(Nsrange) Rangeofunit: (nscalendarunit) smaller inunit: (nscalendarunit) larger fordate: (nsdate *) DateReturns the range of a specific time (date) of its corresponding small time cell (smaller) in a large time cell (larger), such as:. To get 2008/11/12 in the date range of the month in which you can call this method:[Calendar Ordinalityofunit:nsdaycalendarunit inunit:nsmonthcalendaruni
SQL calculates the number of days working between two dates http://blog.163.com/im_foto/blog/static/49085060200953010553914/ -- calculates the number of days working between two dates
Create Function f_workdatediff (
@ Dt_begin datetime,
@ Dt_end datetime)
Returns int
As
Begin
Declare @ workday int, @ I int, @ BZ bit, @ DT datetime
If @ dt_begin> @ dt_end
Select @ Bz = 1, @ dt = @ dt_bsegin, @ dt_begin = @
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.