PHP:日期时间帮助

发布于 2024-10-03 03:43:59 字数 2289 浏览 5 评论 0原文

我知道互联网上有大量有关日期时间的信息,但我在使用我所看到的信息时遇到了麻烦。

我有一个连接到文本框的压延机控件。它采用 15/11/2010(英国)的形式。我用它来查询 SQL Server 数据库中格式为 15/11/2010 00:00:00 的日期时间字段。

捕获回发日期后,我将这些值传递到尝试将文本转换为时间格式的方法。当我在 01/01/2010 和 01/07/2010 之间查询某些内容时,我得到了许多结果。当我将其更改为 01/01/2010 和 30/10/2010 之间时,出现错误。该错误对于each无效(尚未捕获该错误)。我猜这与我的格式有关?

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;
}

任何帮助非常感谢!

琼西

I know there's ample information about datetimes on the internet but I'm having trouble using what I've been seeing.

I have a calander control hooked up to a text box. It takes it in the form 15/11/2010 (british). I use it to query datetime fields in a SQL server db in the format 15/11/2010 00:00:00.

After the capture the dates on postback I pass the values onto my method that attempts to convert the text into time format. When I query for something between 01/01/2010 and 01/07/2010 I get a number of results. When I change this to between 01/01/2010 and 30/10/2010 I get an error. The error is invalid foreach (haven't caught the error yet). I'm guessing its something to do with my formats?

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;
}

Any help most appreciated!

Jonesy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨后彩虹 2024-10-10 03:44:00

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

date("DD/MM/YY ...

这不起作用,因为这不是它们在 PHP 中的格式。这:

date("d/m/y ...

将格式更改为 DD/MM/YY。 :)

http://php.net/manual/en/function.date.php

I'm unsure if you're formatting the dates correctly. You can find all the formatting rules at the bottom through the URL posted

date("DD/MM/YY ...

That's not gonna work cause that's not how they're formatted in PHP. This:

date("d/m/y ...

will change the format to DD/MM/YY. :)

http://php.net/manual/en/function.date.php

夜雨飘雪 2024-10-10 03:44:00

日期(“日/月/年”);将输出 SATSAT/DECDEC/2010201020102010..
很确定你想要date("d/m/Y",...

date("DD/MM/YY"); would output SATSAT/DECDEC/2010201020102010..
pretty sure you're wanting date("d/m/Y",...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文