drasv0904 2011-05-11 21:57
浏览 75
已采纳

如何修改此查询,以便开始/结束日期按天而不是确切时间?

I'm using the query below to get posts based on the start and end dates which use the UNIX timestamp.

Currently, it's only returning results if the start time occurred after today's time. For example, if it's 5:00 PM and the start date is 6:00 PM, it won't pick it up. I would like it to consider anytime during today (from midnight last night to midnight tonight) as being the start date.

Can someone tell me how to update my code to get this to work?

$current_time is equal to 1305132894, which is 5:54 EST today.

'meta_query'        => array(
    array(
        'key'       => 'start_date',
        'value'     => $current_time,
        'compare'   => '<'
    ),
    array(
        'key'       => 'end_date',
        'value'     => $current_time,
        'compare'   => '>'
    )
)
  • 写回答

2条回答 默认 最新

  • douzhong6480 2011-05-11 22:21
    关注

    If you only need it to work for today, you can use:

    $minDate = strtotime('midnight today');
    $maxDate = strtotime('midnight tomorrow -1 second');
    

    or alternatively

    $minDate = mktime(0,0,0);
    $maxDate = mktime(11,59,59);
    

    Some combination of mktime() and strtotime() should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源