Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用BETWEEN的MySQL日期\格式不起作用_Mysql_Sql_Date Format - Fatal编程技术网

使用BETWEEN的MySQL日期\格式不起作用

使用BETWEEN的MySQL日期\格式不起作用,mysql,sql,date-format,Mysql,Sql,Date Format,我使用两个存储函数,它们工作,当放入SELECT时,它们返回正确的值,但是当我尝试减少并获取这些值的子集时,我得到一个没有警告的空集 这是我的SQL SELECT DISTINCT e.ims_event_id, e.name, e.begin_time bUTC, e.end_time eUTC, DATE_FORMAT(DATE_ADD(e.begin_time, INTERVAL ptat_getTZOffset(pp.subject_to_

我使用两个存储函数,它们工作,当放入SELECT时,它们返回正确的值,但是当我尝试减少并获取这些值的子集时,我得到一个没有警告的空集

这是我的SQL

SELECT
    DISTINCT
    e.ims_event_id,
    e.name,
    e.begin_time bUTC,
    e.end_time eUTC,
    DATE_FORMAT(DATE_ADD(e.begin_time, INTERVAL ptat_getTZOffset(pp.subject_to_dlst, tz.delta_time, e.begin_time, country) MINUTE),'%H:%i') begin_local,
    DATE_FORMAT(DATE_ADD(e.end_time, INTERVAL ptat_getTZOffset(pp.subject_to_dlst, tz.delta_time, e.end_time, country) MINUTE),'%H:%i') end_local,
    DATE_FORMAT(ptat_getEventHalfPoint(pp.subject_to_dlst, tz.delta_time, e.begin_time, e.duration, country),'%H:%i') begin_local_halfPoint,
    DATE_FORMAT(DATE_ADD(pp.start_time, INTERVAL ptat_getTZOffset(pp.subject_to_dlst, tz.delta_time, pp.start_time, country) MINUTE),'%H:%i') ptat_begin,
    DATE_FORMAT(DATE_ADD(pp.end_time, INTERVAL ptat_getTZOffset(pp.subject_to_dlst, tz.delta_time, pp.end_time, country) MINUTE),'%H:%i') ptat_end 
FROM
    event e
    JOIN service s ON e.service_uid = s.service_uid
    JOIN service_ptc sp ON s.service_uid = sp.service_uid
    JOIN service_primetime_period spp ON s.service_uid = spp.service_uid
    JOIN primetime_period pp ON spp.primetime_period_uid = pp.primetime_period_uid
    JOIN time_zone tz ON pp.time_zone_id = tz.time_zone_id 
    JOIN dlst_info dli ON country = 'US' AND dli.year = DATE_FORMAT(e.begin_time,'%Y')
WHERE
    (POW(2,DATE_FORMAT(DATE_ADD(e.begin_time,INTERVAL tz.delta_time HOUR), '%w'))&pp.weekdays) > 0 AND
    e.end_time > NOW() AND 
    e.begin_time < DATE_ADD(NOW(),INTERVAL 8 DAY) AND
    DATE_FORMAT(ptat_getEventHalfPoint(pp.subject_to_dlst, tz.delta_time, e.begin_time, e.duration, country),'%H:%i') BETWEEN
DATE_FORMAT(DATE_ADD(pp.start_time, INTERVAL ptat_getTZOffset(pp.subject_to_dlst, tz.delta_time, pp.start_time, country) MINUTE),'%H:%i') AND
    DATE_FORMAT(DATE_ADD(pp.end_time, INTERVAL ptat_getTZOffset(pp.subject_to_dlst, tz.delta_time, pp.end_time, country) MINUTE),'%H:%i')
ORDER BY e.begin_time;
编辑2: 我从所有表中取出所有字段,并将其合并到沙箱中的一个表中。我将这两个函数都设置为静态,以便始终假定我们处于夏令时季节,并添加了示例数据。它起作用了!所以我不得不回溯,我想SQL语法或逻辑并没有什么问题。某些列、某些联接或表失败。我还间歇性地出现以下错误:

Error | 1366 | Incorrect decimal value: '' for column '' at row -1

如果我可以附加一个SQL文件,我可以附加我的测试模式,我不想把它粘贴在这里

我在做项目的时候也发现了一些问题

想要从数据库中筛选记录,这些记录在上午5点到下午1点之间。 我想在查询字符串中传递AM或PM参数。 但是mysql日期格式总是采用24小时格式。上午或下午没关系

select  poll_voting_result_id,poll_master_id,date_voting,date_format(date_voting,'%Y-%m-%d %r') as 12_hour_format_R,
date_format(date_voting,'%Y-%m-%d %H:%i:%s %p') as 24_hour_format_P from poll_voting_result 
where up_down = 0 
and 
poll_master_id = '11' 
and 
date(date_voting) = '2013-03-20' 
and date_format(date_voting,'%H:%i:%s %r') BETWEEN '05:00 AM' and '13:01:06 PM' 
order by date_voting ASC


select  poll_voting_result_id,poll_master_id,date_voting,date_format(date_voting,'%Y-%m-%d %r') as 12_hour_format_R,
date_format(date_voting,'%Y-%m-%d %H:%i:%s %p') as 24_hour_format_P from poll_voting_result 
where up_down = 0 
and 
poll_master_id = '11' 
and 
date(date_voting) = '2013-03-20' 
and date_format(date_voting,'%H:%i:%s %p') BETWEEN '05:00' and '13:01:06' 
order by date_voting ASC
以上两个查询都工作良好。 但我需要通过考试


在“05:00 AM”和“01:01:06 PM”之间

我在做项目的时候也发现了一些问题

想要从数据库中筛选记录,这些记录在上午5点到下午1点之间。 我想在查询字符串中传递AM或PM参数。 但是mysql日期格式总是采用24小时格式。上午或下午没关系

select  poll_voting_result_id,poll_master_id,date_voting,date_format(date_voting,'%Y-%m-%d %r') as 12_hour_format_R,
date_format(date_voting,'%Y-%m-%d %H:%i:%s %p') as 24_hour_format_P from poll_voting_result 
where up_down = 0 
and 
poll_master_id = '11' 
and 
date(date_voting) = '2013-03-20' 
and date_format(date_voting,'%H:%i:%s %r') BETWEEN '05:00 AM' and '13:01:06 PM' 
order by date_voting ASC


select  poll_voting_result_id,poll_master_id,date_voting,date_format(date_voting,'%Y-%m-%d %r') as 12_hour_format_R,
date_format(date_voting,'%Y-%m-%d %H:%i:%s %p') as 24_hour_format_P from poll_voting_result 
where up_down = 0 
and 
poll_master_id = '11' 
and 
date(date_voting) = '2013-03-20' 
and date_format(date_voting,'%H:%i:%s %p') BETWEEN '05:00' and '13:01:06' 
order by date_voting ASC
以上两个查询都工作良好。 但我需要通过考试


在'05:00 AM'和'01:01:06 PM'之间

如果WHERE子句中没有包含这3行,您能否向我们展示一个返回的示例行?因此,请澄清我要查找的内容。如果你看样品日。我在寻找eventHalfPoint第7列位于第8列和最后一列之间的行。所以所有这些行都应该返回。19:30介于19:00和22:00之间以及18:00和22:00之间,请参见最后3行。当您在WHERE中包含前3个编码时,是否返回这些行?是。只有子句的最后3行使其返回空结果。OK。如果您确认您提供的示例是通过一个查询返回的,该查询包括WHERE POW2、DATE_FORMATDATE_ADDe.begin_time、INTERVAL tz.delta_time HOUR、“%w”和pp.weekdays>0和e.end_time>NOW以及e.begin_time0和e.end_time>NOW以及e.begin_time