首页 \ 问答 \ 除自定义期间之间的日期差异(difference between dates excluding custom periods)

除自定义期间之间的日期差异(difference between dates excluding custom periods)

早上好,

我需要一个解决方案来计算特定日期之间的天数。 此外,我需要排除特定日期(公众假期和周末),这很容易,并且有很多关于如何做的说明。

但我还需要做一件事。 对于每个人,我也有自定义休假期,我需要从之前的结果中减去它们。

目前,我有两张桌子。 一个用于定制度假期间:

+-----+----------+---------------------+---------------------+------+
| id  | employee | start               | end                 | away |
+-----+----------+---------------------+---------------------+------+
| 835 | 2.3      | 2016-12-05 00:00:00 | 2016-12-10 00:00:00 | P    |
| 836 | 5.3.5.1  | 2017-01-03 00:00:00 | 2017-01-23 00:00:00 | P    |
| 837 | 5.3.5.6  | 2016-12-21 00:00:00 | 2017-04-01 00:00:00 | P    |
| 838 | 5.3.3.1  | 2017-01-01 00:00:00 | 2017-01-03 00:00:00 | P    |
| 839 | 5.3.1.2  | 2017-01-03 00:00:00 | 2017-01-12 00:00:00 | P    |
| 840 | 5.3.1.6  | 2017-01-01 00:00:00 | 2017-01-01 00:00:00 | P    |
| 841 | 5.1.7    | 2017-01-09 00:00:00 | 2017-01-15 00:00:00 | P    |
| 842 | 2.2      | 2017-02-16 00:00:00 | 2017-02-26 00:00:00 | P    |
| 843 | 2.5      | 2017-07-31 00:00:00 | 2017-08-06 00:00:00 | P    |
| 844 | 2.5      | 2017-08-21 00:00:00 | 2017-08-27 00:00:00 | P    |
| 845 | 2.5      | 2017-06-26 00:00:00 | 2017-07-09 00:00:00 | P    |
| 846 | 2.4      | 2017-04-04 00:00:00 | 2017-04-08 00:00:00 | P    |
+-----+----------+---------------------+---------------------+------+
12 rows in set (0.00 sec)

我在开始和结束时有日期和时间的原因是该表实际上也有关于他们的工作时间表的信息。 休假计划标记为“离开”列设置为“P”。

第二个表看起来像这样:

+-----------+-------------+------+-----+---------+----------------+
| Field     | Type        | Null | Key | Default | Extra          |
+-----------+-------------+------+-----+---------+----------------+
| id        | int(11)     | NO   | PRI | NULL    | auto_increment |
| date      | varchar(45) | YES  |     | NULL    |                |
| dayofweek | varchar(45) | YES  |     | NULL    |                |
| short     | varchar(45) | YES  |     | NULL    |                |
| holiday   | varchar(45) | YES  |     | NULL    |                |
+-----------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

这个表基本上是一个日历,其中包含有关星期几的其他信息(我知道这可以通过dayofweek()完成,但我也需要此列),'short'确定它是否是缩短的工作日(在计算小时数时必不可少)因为工作日较短的一年中有几天而公共假期是“假期”。

我试图通过减去公共假日和周末(我可以做并且相对容易)来计算如何计算一个月(2017年8月1日 - 2017年8月31日)的工作日,并减去自定义的假期。 主要问题是,对于某些人来说,一个月内可能会有一个以上的缺席期。

如果您查看上面的示例,员工2.5的休假期从7月开始到8月结束,我只需要减去该期间8月份的金额。 员工2.5在8月有另一个假期,我也需要减去这个假期。 除此之外,该员工在6月至7月期间还有另一个假期。

完美的结果将是这样的:

+----------+-------+---------------+--------------+---------------+
| employee | month | working hours | working days | vacation days |
+----------+-------+---------------+--------------+---------------+

我能够想出的唯一解决方案是创建一个名为vacations的新表,每天都有一列,每行显示一名员工的数据。 或者另一种方式是员工是列和行的日期。 但在我知道没有更容易的方法之前,我不想开始玩这个想法。

再一次,我确信在mysql中有一个简单的功能,但我无法弄明白。


Good morning,

I need a solution for counting days between specific dates. In addition I need to exclude specific dates (public holidays and weekends), which is easy and there are plenty of instructions on how to do it.

But I need to accomplish one more thing. For every person, I also have custom vacation periods and I need them to be subtracted from the previous result.

At the moment, i have two tables. One for the custom vacation periods:

+-----+----------+---------------------+---------------------+------+
| id  | employee | start               | end                 | away |
+-----+----------+---------------------+---------------------+------+
| 835 | 2.3      | 2016-12-05 00:00:00 | 2016-12-10 00:00:00 | P    |
| 836 | 5.3.5.1  | 2017-01-03 00:00:00 | 2017-01-23 00:00:00 | P    |
| 837 | 5.3.5.6  | 2016-12-21 00:00:00 | 2017-04-01 00:00:00 | P    |
| 838 | 5.3.3.1  | 2017-01-01 00:00:00 | 2017-01-03 00:00:00 | P    |
| 839 | 5.3.1.2  | 2017-01-03 00:00:00 | 2017-01-12 00:00:00 | P    |
| 840 | 5.3.1.6  | 2017-01-01 00:00:00 | 2017-01-01 00:00:00 | P    |
| 841 | 5.1.7    | 2017-01-09 00:00:00 | 2017-01-15 00:00:00 | P    |
| 842 | 2.2      | 2017-02-16 00:00:00 | 2017-02-26 00:00:00 | P    |
| 843 | 2.5      | 2017-07-31 00:00:00 | 2017-08-06 00:00:00 | P    |
| 844 | 2.5      | 2017-08-21 00:00:00 | 2017-08-27 00:00:00 | P    |
| 845 | 2.5      | 2017-06-26 00:00:00 | 2017-07-09 00:00:00 | P    |
| 846 | 2.4      | 2017-04-04 00:00:00 | 2017-04-08 00:00:00 | P    |
+-----+----------+---------------------+---------------------+------+
12 rows in set (0.00 sec)

The reason I have date and time on start and end is that the table actually has info about their working schedule also. The vacation schedule is marked by column 'away' set as 'P'.

The second table looks like this:

+-----------+-------------+------+-----+---------+----------------+
| Field     | Type        | Null | Key | Default | Extra          |
+-----------+-------------+------+-----+---------+----------------+
| id        | int(11)     | NO   | PRI | NULL    | auto_increment |
| date      | varchar(45) | YES  |     | NULL    |                |
| dayofweek | varchar(45) | YES  |     | NULL    |                |
| short     | varchar(45) | YES  |     | NULL    |                |
| holiday   | varchar(45) | YES  |     | NULL    |                |
+-----------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

This table is basically a calendar with additional information about what day of week it is (i know that this can be done with dayofweek() but i need this column also), 'short' determines whether it's a shortened workday (essential when calculating hours because there are a couple of days in a year when the working day is shorter) and 'holiday' which marks public holidays.

I am trying to figure out how to calculate working days during one month (01.08.2017 - 31.08.2017) by subtracting public holidays and weekends (which I can do and is relatively easy) and also subtract custom period of vacations. The main problem is that for some people, there can be more than one period of absence during one month.

If you look at the example above, employee 2.5 has a vacation period that starts in July and ends in August and I need to subtract only the amount in that period that is in August. Employee 2.5 has another vacation in August and I need to subtract this also. In addition to that, this employee has another vacation from June to July.

The perfect outcome would be something like this:

+----------+-------+---------------+--------------+---------------+
| employee | month | working hours | working days | vacation days |
+----------+-------+---------------+--------------+---------------+

The only solution I am able to come up with is to create a new table called vacations with a column for each day and each row shows data for one employee. Or the other way around where employees are columns and rows are dates. But I would not like to start playing with this idea before i know that there isn't an easier way to do it.

Once again, I am sure that there is an easy function in mysql for this but I fail to figure it out.


原文:https://stackoverflow.com/questions/41218919
更新时间:2024-04-27 21:04

最满意答案

好的解决这个糟糕的坏问题,就是在prod环境中杀死我的应用而没有任何办法解决它,只是我把config.yml这个:

services:
    assets.packages:
        synthetic: true

通过魔术,它有效......

我真的很想尝试解决那些应该开箱即用的东西......


problem was in FPNTagBundle, i remove it and error gone...

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)