PHP: DATETIME Help
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!
Answer:
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://stackoverflow.com/questions/4188954/php-datetime-help
COMMENTS