PHP:DATETIME帮助

PHP:DATETIME帮助,php,datetime,strtotime,datetime-format,Php,Datetime,Strtotime,Datetime Format,我知道网上有很多关于日期时间的信息,但是我在使用我看到的东西时遇到了麻烦 我有一个连接到文本框的calander控件。它以2010年11月15日(英国)的形式出现。我使用它以15/11/2010 00:00:00的格式查询SQL server db中的datetime字段 捕获回发日期后,我将值传递到我的方法,该方法尝试将文本转换为时间格式。当我查询2010年1月1日至2010年7月1日之间的内容时,我会得到许多结果。当我将其更改为介于2010年1月1日和2010年10月30日之间时,我得到一个

我知道网上有很多关于日期时间的信息,但是我在使用我看到的东西时遇到了麻烦

我有一个连接到文本框的calander控件。它以2010年11月15日(英国)的形式出现。我使用它以15/11/2010 00:00:00的格式查询SQL server db中的datetime字段

捕获回发日期后,我将值传递到我的方法,该方法尝试将文本转换为时间格式。当我查询2010年1月1日至2010年7月1日之间的内容时,我会得到许多结果。当我将其更改为介于2010年1月1日和2010年10月30日之间时,我得到一个错误。错误foreach无效(尚未捕获错误)。我猜这和我的格式有关

function getSupportTicketsbySubIssueAndDate($subissueid, $from, $to){

    $subissueid = $this->ms_escape_string($subissueid);

    $from = date("DD/MM/YY", strtotime($from));
    $to = date("DD/MM/YY", strtotime($to));

    $connection = new Connections();
    $conn = $connection->connectToWarehouse();
    $atid = $_SESSION['saveddata']['autotaskid'];


    $tsql = "SELECT wh_task.task_id, wh_task.task_name, wh_task.task_description, wh_task.task_number, wh_task.reported_by_name, wh_task.create_time, wh_resource.first_name, wh_resource.last_name, wh_task_status.task_status_name ".
            "FROM wh_task_status INNER JOIN (wh_task INNER JOIN wh_resource ON wh_task.assigned_resource_id = wh_resource.resource_id) ON wh_task_status.task_status_id = wh_task.task_status_id ".
            "WHERE (account_id = $atid) AND (subissue_type_id = $subissueid) AND (((wh_task.create_time) Between '$from' And '$to'))".
            "ORDER BY create_time DESC";


    // set up array to hold each of the issue types and the number of tickets in each
    $ticket;

    $stmt = sqlsrv_query( $conn, $tsql);
    if( $stmt === false)
    {
             echo "Error in query preparation/execution.\n";
             die( print_r( sqlsrv_errors(), true));
    }

    $x = 0;
    /* Retrieve each row as an associative array and display the results.*/
    while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
    {
            $ticket[$x][0] = $row['task_name'];
            $ticket[$x][1] = $row['task_description'];
            $ticket[$x][2] = $row['task_number'];
            $ticket[$x][3] = $row['reported_by_name'];
            $ticket[$x][4] = $row['first_name'];
            $ticket[$x][5] = $row['last_name'];
            $ticket[$x][6] = $row['task_status_name'];
            $ticket[$x][7] = $row['create_time'];
            $ticket[$x][8] = $row['task_id'];

            $x++;
    }

    return $ticket;
}
非常感谢您的帮助


琼斯

我不确定你的日期格式是否正确。您可以通过发布的URL在底部找到所有格式规则

date("DD/MM/YY ...
这是行不通的,因为PHP中的格式不是这样的。这:

date("d/m/y ...
将格式更改为DD/MM/YY.:)

日期(“日/月/年”);将输出SATSAT/DECDEC/20102001020102010..

很确定你想要的是
日期(“d/m/Y”,…

我想你也需要将datetime转换为MySQL。如果我将其转换为这种格式,并选择2010年1月13日和2010年11月13日,当我回显转换后的日期时,它们显示为1970年1月1日和1970年1月1日,那么你的时间戳是错误的,即strotime没有正确解析$form和$to。D/m/y将把日期打印为te但是xt?如果您需要获取日期字符串的unix时间戳,strotime($str)函数非常好。哦,该死的,我的意思是小d:)