- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要在现有项目上实现一些事件的显示。我无法更改数据库结构。
在我的 Controller 中,我(从 ajax 请求)传递了一个时间戳,并且我需要显示之前的 8 个事件。因此,如果时间戳是(转换后)2017-12-12 00:00:00,我需要显示 2017-12-12 之前的 8 个事件,按时间 DESC 排序。
这就是我的表格的设置方式:
-calendarrepeat
-dayofweek // int 1-7; 1 = monday, 7 = sunday
-event_date_begin // date "2016-05-01" - indicates from which day the event recurrs every week (dayofweek)
-event_date_end // date "2017-05-02" - indicates until which day the event recurrs every week (dayofweek)
-event_hour_begin // time "11:00:00"
-event_hour_end // time "12:00:00"
我可以用时间戳做任何我想做的事。我用Carbon因此,获取一年中的星期、一年中的某一天或我需要的其他任何内容都不是问题。
供引用$fullTs
是我传递到 Controller 的时间戳。连接部分工作正常。
我需要帮助的部分是:/* THIS PART has to be rewritten (it's COMPLETELY wrong at the moment) ! */
我需要从年份(作为参数传递)、weekOfYear(作为参数传递)、星期几(从数据库列)和时间(数据库列)生成时间戳图。我需要这样的东西(pseudoSQL):
->where(\DB::raw('THISTHINGY_TO_DATE($fullTs->year $fullTs->weekOfYear calendarrepeat.dayofweek calendarrepeat.event_hour_begin, "%Y %week-of-year %day-of-week %H:%i:%s), '<', $fullTs)))
这是我当前正在运行的完整查询(UNION 的第一部分,第二部分按预期工作):
$eventsRepeat = CalendarRepeat::join('calendarrepeat_translations', function ($j) use ($locale) {
$j->on('calendarrepeat.id', '=', 'calendarrepeat_translations.calendarrepeat_id')
->where('calendarrepeat_translations.locale', '=', $locale);
})
->orderBy('calendarrepeat.event_date_begin', $orderBy)
/* THIS PART has to be rewritten (it's COMPLETELY wrong at the moment) ! */
/* the STR_TO_DATE(..) part has to get date from a) week passed in $fullTs b) dayoftheweek written in calendarrepeat.dayoftheweek c) time written in calendarrepeat.event_hour_begin */
->where(\DB::raw("STR_TO_DATE(CONCAT(calendarrepeat.event_date_begin, ' ', calendarrepeat.event_hour_begin), '%Y-%m-%d %H:%i:%s')"), '<', $fullTs)
->where('event_date_begin', '>', $fullTs)
->where('event_date_end', '<', $fullTs)
->limit(8)
->select([
'calendarrepeat.event_date_begin as date', 'calendarrepeat.event_hour_begin as start',
'calendarrepeat.event_hour_end as end', 'calendarrepeat_translations.title as title', \DB::raw("CONCAT(calendarrepeat.event_date_begin, ' ', calendarrepeat.event_hour_begin) as date_whole") // This is also wrong
]);
这可能吗?如何?有没有更好的方法来做到这一点?
另一件需要注意的事情是,在我们的数据库中,1 = 星期一,7 = 星期日,据我了解,这不是枚举工作日的常用方法。
提前致谢。
最佳答案
尝试一下并检查您得到的结果:
$eventsRepeat = CalendarRepeat::join('calendarrepeat_translations', function ($j) use ($locale) {
$j->on('calendarrepeat.id', '=', 'calendarrepeat_translations.calendarrepeat_id')
->where('calendarrepeat_translations.locale', '=', $locale);
})->select([
'calendarrepeat.id',
'calendarrepeat_translations.calendarrepeat_id',
'calendarrepeat_translations.locale','calendarrepeat.event_date_begin as date',
'calendarrepeat.event_hour_begin as start',
'calendarrepeat.event_hour_end as end',
'calendarrepeat_translations.title as title',
\DB::raw("CONCAT(calendarrepeat.event_date_begin, ' ', calendarrepeat.event_hour_begin) as date_whole")
])->where(\DB::raw("STR_TO_DATE(CONCAT(date, ' ', start), '%Y-%m-%d %H:%i:%s')"), '<', $fullTs)
->where('date', '>', $fullTs)
->where('end', '<', $fullTs)
->orderBy('date', $orderBy)
->limit(8);
关于php - MySQL如何从年份(参数)、weekOfYear(参数)、时间(数据库)和dayofweek(数据库)创建时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44029852/
我想获取两个 DayOfWeeks 之间的 DayOfWeeks 列表。 例如, Input1: DayOfWeek.MONDAY Input2: DayOfWeek.WEDNESDAY 并且输出应该
有没有办法把这段代码总结成1-2行? 我的目标是返回,例如,我有一个 DayOfWeek 是星期一,我想得到之后的一天(星期二)或之后的 n 天。 switch (_RESETDAY
我正在像这样解析日期:"Sat, 30 Jan 2016 00:03:00 +0300" 但在某些日期它抛出这个异常: Caused by: java.time.DateTimeException:
一周中的某几天是否有英文(或特定于程序员的)单一字符约定,如果有的话,这是什么?我意识到这可能是一个英语问题,但我认为它对程序员特别重要。 也许像这样: Monday Mon MO M Tu
如何获取给定年份任何的一周的第一天(日期为 1 到 7,或工作日名称)? 我尝试用 JavaScript 来解决,但我接受任何其他语言。 我需要选择一年来构建完整的日历(我想使用 HTML 表格和 J
如何获取上周的 DayOfWeek 日期? 例如 我想选择 6 月 23 日星期日作为 DayOfWeek? 我只能得到这周的DayOfWeek。 这是我的代码 DateTime today = Da
我正在使用DAYOFWEEK() MySQL 中的函数,对于星期日返回1。但在我的国家,一周从星期一开始,而不是星期日。是否有机会从 MySQL 获取星期几,格式如下:(1 - 星期一,2 - 星期二
我正在寻找一种在 MySQL 中将整数 (0-6) 转换为星期几的方法,例如: EXAMPLE_FUNCTION(3) = Wednesday. DAYOFWEEK(date)函数接受一个日期并给你一
我需要将工作日名称解析为 DayOfWeek。工作日名称可以是短格式('Mon')或长格式('Monday')。 目前我想出了这样的解决方案: DateTimeFormatter dtf = Date
在工作中,我们需要生成一份 6 个月大的报告。基本上,从5月1日到11月1日,报告必须以周为基础。到目前为止,我一次只能手动完成一周... 这是我的代码 SELECT displayname, cap
我们有 DayOfWeek在标准 ISO 8601 中定义星期几的枚举命令。 我想要一个 List这些对象的顺序适合 Locale . 我们可以很容易地确定语言环境一周的第一天。 Locale loc
我正在使用 DAYOFWEEK() MySQL 中的函数,它为 sunday 返回 1。但在我的国家,一周从星期一开始,而不是星期日。是否有机会从 MySQL 获取 dayofweek 格式如下:(1
我有一个表示星期几的简单整数列表。我正在尝试检查我的实体的 Date 属性是否在选定的一周内。但是,如果我尝试在针对数据库的查询中传递它,如下所示: query.Where(e => selected
我不知道如何在 .NET 2.0 中正确本地化 DateTime.DayOfWeek。 例子: DateTime date = DateTime.Now; // Works fine string l
这可能是一个新手问题,但这里是。 我有一种方法,其中类型 DayOfWeek 列表会附加一周中的不同日期(可能是星期三和星期六、星期日、星期一和星期五等)。 给定该列表,我需要将其与日期时间参数进行比
有没有可能得到DayOfWeek针对特定文化? 有什么线索吗? 谢谢!!! 最佳答案 尝试以下操作: DateTime.Now.ToString("dddd", new System.Globaliz
我正在尝试获取一个查询,该查询将返回一个结果集,其中包含特定小时范围内的读取总数(在 working_hours 表中定义),具体取决于 DAYOFTHEWEEK 的日期,结果如下: working
我有一个每周不同日期发生的事件列表。我希望我的查询返回从今天开始按星期几排序的结果。 'Meeting_Day' = Sunday, Monday, Tuesday... 'Day_of_Week'
我有下表 Specialoffer Id (int) ValidFrom (date) ValidTo (date) SpecialOfferExcludedDays Id (int) (F
我正在尝试计算一个值,其中我从工作日和一年中的前 3 个月获得计数。 SELECT SUM(count_LP) AS down1 FROM `splittest` WHERE DAYOFWEE
我是一名优秀的程序员,十分优秀!