


Calculate the number of days from January 1, 2000 to the specified day_PHP tutorial
This is a function that calculates the number of days from January 1, 2000 to the specified day
(the beginning and the end are also counted) The date format is: YYYY-MM-DD
// Calculate the number of days from January 1, 2000 to a certain day
function cal_start2end($end_day,$start_day)
{
$start_day=ereg_replace("-","",$start_day);
$end_day=ereg_replace("-","",$end_day);
if($end_day>=$start_day)
{ // The end date is greater than the start date
if(substr($end_day,0,4)==substr($start_day,0,4) )
28;
// the same month
$endday_from_startday=$end_day-$start_day+1;
}
else
{
// not same month
switch (substr($end_day,4,2))
{
case "01":
$endday_from_newyear=substr($end_day,6,2)+1;
break;
case "02":
$endday_from_newyear=substr($end_day,6,2)+31;
break;
case "03":
$endday_from_newyear=substr($end_day,6,2)+$leap_day+31;
break;
case "04":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*2;
break;
case "05":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*2+30;
break;
case "06":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*3+30;
break;
case "07":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*2+30*2;
break;
case "08":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*3+30*2;
break;
case "09":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*5+30*2;
break;
case "10":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*5+30*3;
break;
case "11":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*5+30*4;
break;
case "12":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*5+30*5;
break;
}
$endday_from_startday=$endday_from_newyear;
}
return ($endday_from_startday);
}
else
{
// 不同年!
$differ_year=substr($end_day,0,4)-substr($start_day,0,4);
$how_int_4_floor=floor($differ_year/4)+1; // 向下取整
$how_int_4_ceil=ceil($differ_year/4)+1; // 向上取整
if($how_int_4_floor==$how_int_4_ceil)
$how_leap_year=$how_int_4_floor-1;
else
$how_leap_year=$how_int_4_floor;
$how_noleap_year=$differ_year-$how_leap_year;
$differ_year2day=$how_noleap_year*365+$how_leap_year*366;
if( is_int(substr($end_day,0,4)/4) )
$leap_day=29; //leap year
else
$leap_day=28;
if(substr($end_day,4,2)==substr($start_day,4,2))
{
// the same month
$endday_from_startday=$differ_year2day+ substr($end_day,4,2);
}
else
{
// not same month
switch (substr($end_day,4,2))
{
case "01":
$endday_from_newyear=substr($end_day,6,2)+1;
break;
case "02":
$endday_from_newyear=substr($end_day,6,2)+1+31;
break;
case "03":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31;
break;
case "04":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*2;
break;
case "05":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*2+30;
break;
case "06":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*3+30;
break;
case "07":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*2+30*2;
break;
case "08":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*3+30*2;
break;
case "09":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*5+30*2;
break;
case "10":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*5+30*3;
break;
case "11":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*5+30*4;
break;
case "12":
$endday_from_newyear=substr($end_day,6,2)+1+$leap_day+31*5+30*5;
break;
} //End of switch
$endday_from_startday=$endday_from_newyear+$differ_year2day;
} //End of not same month
return ($endday_from_startday);
} //End of year
} //End of $end_day>=$start_day
} //End of function
$start_day="2000-01-01";
$end_day="2011-01-01";
echo "您输入的是:".$end_day."
n";
$endday_from_startday=cal_start2end($end_day,$start_day);
echo "该日距离$start_day 共 ".$endday_from_startday." 天";
?>
时间太少了,那位大虾可以修改为计算任意两日期之间的间隔最好!!!!!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

WORD is a powerful word processor. We can use word to edit various texts. In Excel tables, we have mastered the calculation methods of addition, subtraction and multipliers. So if we need to calculate the addition of numerical values in Word tables, How to subtract the multiplier? Can I only use a calculator to calculate it? The answer is of course no, WORD can also do it. Today I will teach you how to use formulas to calculate basic operations such as addition, subtraction, multiplication and division in tables in Word documents. Let's learn together. So, today let me demonstrate in detail how to calculate addition, subtraction, multiplication and division in a WORD document? Step 1: Open a WORD, click [Table] under [Insert] on the toolbar, and insert a table in the drop-down menu.

General Matrix Multiplication (GEMM) is a vital part of many applications and algorithms, and is also one of the important indicators for evaluating computer hardware performance. In-depth research and optimization of the implementation of GEMM can help us better understand high-performance computing and the relationship between software and hardware systems. In computer science, effective optimization of GEMM can increase computing speed and save resources, which is crucial to improving the overall performance of a computer system. An in-depth understanding of the working principle and optimization method of GEMM will help us better utilize the potential of modern computing hardware and provide more efficient solutions for various complex computing tasks. By optimizing the performance of GEMM

How to set up keyboard startup on Gigabyte's motherboard. First, if it needs to support keyboard startup, it must be a PS2 keyboard! ! The setting steps are as follows: Step 1: Press Del or F2 to enter the BIOS after booting, and go to the Advanced (Advanced) mode of the BIOS. Ordinary motherboards enter the EZ (Easy) mode of the motherboard by default. You need to press F7 to switch to the Advanced mode. ROG series motherboards enter the BIOS by default. Advanced mode (we use Simplified Chinese to demonstrate) Step 2: Select to - [Advanced] - [Advanced Power Management (APM)] Step 3: Find the option [Wake up by PS2 keyboard] Step 4: This option The default is Disabled. After pulling down, you can see three different setting options, namely press [space bar] to turn on the computer, press group

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

How to use Python's count() function to calculate the number of an element in a list requires specific code examples. As a powerful and easy-to-learn programming language, Python provides many built-in functions to handle different data structures. One of them is the count() function, which can be used to count the number of elements in a list. In this article, we will explain how to use the count() function in detail and provide specific code examples. The count() function is a built-in function of Python, used to calculate a certain

In C#, there is a Math class library, which contains many mathematical functions. These include the function Math.Pow, which calculates powers, which can help us calculate the power of a specified number. The usage of the Math.Pow function is very simple, you only need to specify the base and exponent. The syntax is as follows: Math.Pow(base,exponent); where base represents the base and exponent represents the exponent. This function returns a double type result, that is, the power calculation result. Let's

Given two strings str_1 and str_2. The goal is to count the number of occurrences of substring str2 in string str1 using a recursive procedure. A recursive function is a function that calls itself within its definition. If str1 is "Iknowthatyouknowthatiknow" and str2 is "know" the number of occurrences is -3. Let us understand through examples. For example, input str1="TPisTPareTPamTP", str2="TP"; output Countofoccurrencesofasubstringrecursi

Glodon Software is a software company focusing on the field of building informatization. Its products are widely used in all aspects of architectural design, construction, and operation. Due to the complex functions and large data volume of Glodon software, it requires high computer configuration. This article will elaborate on the computer configuration recommendations of Glodon Software from many aspects to help readers choose a suitable computer configuration processor. Glodon Software requires a large amount of data calculation and processing when performing architectural design, simulation and other operations. Therefore, the requirements for the processor are higher. It is recommended to choose a multi-core, high-frequency processor, such as Intel i7 series or AMD Ryzen series. These processors have strong computing power and multi-thread processing capabilities, and can better meet the needs of Glodon software. Memory Memory is affecting computing
