Calculate the date after a specified working day_PHP Tutorial
In a recent project, I need to use such a function to calculate the date after N working days. Now I think of the following solution and it seems that it can solve the problem.
Under this explanation, working days are still calculated according to national regulations, that is, Monday to Friday, and those who need to work before and after statutory holidays are counted as working days, while Saturdays, Sundays and statutory holidays are not counted as work. Days, statutory holidays and days off work can be stored in the database for maintenance.
The code is as follows. I feel it is not very efficient. If there is a better way, please share it with experts.
<?<span php date_default_timezone_set(</span>"Asia/Shanghai");<span //</span><span 设置好一个时区</span> <span $now</span>=<span mktime</span>(0, 0, 0,8,1,2013);<span //</span><span 开始的日期,可以是现在或其他你想要的某一个日期的时间戳,这里设置2013-08-01</span> <span $i</span>=10;<span //</span><span 要求计数的工作日数量</span> <span /*</span><span 国家法定假日一般可以存储在数据库中进行维护,包括休假的日期,和周末调休上班的日期两类,作为演示对应日期暂时放在数组中</span><span */</span> <span $working</span>=<span array</span>(<span mktime</span>(0, 0, 0,8,3,2013),<span mktime</span>(0, 0, 0,8,11,2013));<span //</span><span 周末调休上班的日期</span> <span $holiday</span>=<span array</span>(<span mktime</span>(0, 0, 0,8,8,2013),<span mktime</span>(0, 0, 0,8,6,2013));<span //</span><span 法定假期</span> <span $day</span>=<span date</span>("d",<span $now</span>);<span //</span><span 把当天的日期给一个变量</span> <span $w</span>=0;<span //</span><span 工作日计数变量</span> <span while</span>(<span $w</span><<span $i</span>){<span //</span><span 当达到要求的工作日数量则停止循环</span> <span $newdate</span>=<span mktime</span>(0, 0, 0,<span date</span>("m",<span $now</span>),++<span $day</span>,<span date</span>("Y",<span $now</span>));<span //</span><span 加一天输出新的时间戳</span> <span if</span>(<span in_array</span>(<span $newdate</span>, <span $working</span>)){<span //</span><span 判断一下,如果属于调休的则工作日计数加一,如果法定假日调休存在数据库中,则这里需要一条查询语句来查询一下</span> <span $w</span>++<span ; }</span><span else</span>{<span //</span><span 如不属于调休的则再进行判断,既不是周六周日,也不是法定假日,则工作日计数再加上一</span> <span if</span>(<span date</span>("w",<span $newdate</span>)!=0&&<span date</span>("w",<span $newdate</span>)!=6&&!<span in_array</span>(<span $newdate</span>, <span $holiday</span><span )){ </span><span $w</span>++<span ; } } } </span><span echo</span> <span date</span>("Y-m-d",<span $newdate</span>);<span //</span><span 最后得出的时间戳就是要求的10个工作日后的日期了。</span> ?>

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



1. First open the mobile web browser, search for the Weibo web version, and click the avatar button in the upper left corner after entering. 2. Then click Settings in the upper right corner. 3. Click the version switching option in settings. 4. Then select the color version option in the version switch. 5. Click Search to enter the search page. 6. After entering the keywords, click Find People. 7. When the search completion interface appears, click Filter. 8. Finally, enter the specific date in the release time column and click Filter.

There will be many AI creation functions in the Doubao app, so what functions does the Doubao app have? Users can use this software to create paintings, chat with AI, generate articles for users, help everyone search for songs, etc. This function introduction of the Doubao app can tell you the specific operation method. The specific content is below, so take a look! What functions does the Doubao app have? Answer: You can draw, chat, write articles, and find songs. Function introduction: 1. Question query: You can use AI to find answers to questions faster, and you can ask any kind of questions. 2. Picture generation: AI can be used to create different pictures for everyone. You only need to tell everyone the general requirements. 3. AI chat: can create an AI that can chat for users,

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

Both vivox100s and x100 mobile phones are representative models in vivo's mobile phone product line. They respectively represent vivo's high-end technology level in different time periods. Therefore, the two mobile phones have certain differences in design, performance and functions. This article will conduct a detailed comparison between these two mobile phones in terms of performance comparison and function analysis to help consumers better choose the mobile phone that suits them. First, let’s look at the performance comparison between vivox100s and x100. vivox100s is equipped with the latest

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.

1. Let me first talk about the method I used at the beginning, maybe everyone is using it too. First, open [View]——]Remarks Template[. 2. A place where you can actually see the date after opening it. 3. Select it first and delete it. 4. After deleting, click [Close Master View]. 5. Open the print preview again and find that the date is still there. 6. In fact, this date was not deleted here. It should be in the [Handout Master]. Look at the picture below. 7. Delete the date after you find it. 8. Now when you open the preview and take a look, the date is no longer there. Note: In fact, this method is also very easy to remember, because the printed handouts are handouts, so you should look for the [Handout Master].

With the rapid development of the Internet, the concept of self-media has become deeply rooted in people's hearts. So, what exactly is self-media? What are its main features and functions? Next, we will explore these issues one by one. 1. What exactly is self-media? We-media, as the name suggests, means you are the media. It refers to an information carrier through which individuals or teams can independently create, edit, publish and disseminate content through the Internet platform. Different from traditional media, such as newspapers, television, radio, etc., self-media is more interactive and personalized, allowing everyone to become a producer and disseminator of information. 2. What are the main features and functions of self-media? 1. Low threshold: The rise of self-media has lowered the threshold for entering the media industry. Cumbersome equipment and professional teams are no longer needed.

As Xiaohongshu becomes popular among young people, more and more people are beginning to use this platform to share various aspects of their experiences and life insights. How to effectively manage multiple Xiaohongshu accounts has become a key issue. In this article, we will discuss some of the features of Xiaohongshu account management software and explore how to better manage your Xiaohongshu account. As social media grows, many people find themselves needing to manage multiple social accounts. This is also a challenge for Xiaohongshu users. Some Xiaohongshu account management software can help users manage multiple accounts more easily, including automatic content publishing, scheduled publishing, data analysis and other functions. Through these tools, users can manage their accounts more efficiently and increase their account exposure and attention. In addition, Xiaohongshu account management software has
