doucuyu2259 2019-04-18 19:26
浏览 68

PHP / MSSQL获取跨越多个日期的日期的第一个条目

I'm grabbing the results from a query using a PHP webpage from a MSSQL database of entries between x and y dates. Some of those, as shown below, have multiple times per day. When trying to get an output for each day's start time, i'm unsure how to do that. Would this be best done with SQL query manipulation or in PHP looping?

Actual output:

Apr 16 2019 3:00PM
Apr 19 2019 4:00PM
Apr 20 2019 9:00AM
Apr 20 2019 9:30AM
Apr 20 2019 9:40AM
Apr 20 2019 1:20PM
Apr 21 2019 2:00PM

Desired output:

Apr 16 2019 3:00PM
Apr 19 2019 4:00PM
Apr 20 2019 9:00AM
Apr 21 2019 2:00PM
  • 写回答

1条回答 默认 最新

  • dongpin1850 2019-04-18 19:28
    关注

    You could do this via query:

    SELECT MIN(CAST(datestr AS datetime)) AS mindatetime
    FROM t
    GROUP BY CAST(datestr AS date)
    

    Having said that, do not store datetime data as formatted strings, store it as datetime datatype and format it using CONVERT or FORMAT functions. Or PHP.

    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本