Update datetime test, added more comments

This commit is contained in:
David Puglielli 2018-03-09 14:28:25 -08:00
parent 194d4fe0d6
commit f8af52bf26

View file

@ -6,6 +6,10 @@ Test various date and time types with AE and ReturnDatesAsStrings set to true
<?php <?php
// Check for expected errors. These are expected in cases where the dates and // Check for expected errors. These are expected in cases where the dates and
// times do not comply with ODBC standards. // times do not comply with ODBC standards.
// 07006 Restricted data type attribute violation (Conversion failed)
// 22007 Invalid datetime format (ODBC accepts only a few formats)
// 22008 Datetime field overflow (Outside range)
// 22018 Invalid character value for cast specification
function ExecutePreparedStmt($stmt) function ExecutePreparedStmt($stmt)
{ {
if ($stmt == false) { if ($stmt == false) {
@ -14,10 +18,10 @@ function ExecutePreparedStmt($stmt)
$r = sqlsrv_execute($stmt); $r = sqlsrv_execute($stmt);
if ($r == false) { if ($r == false) {
$errors = sqlsrv_errors(); $errors = sqlsrv_errors();
if ($errors[0]['SQLSTATE'] != '22018' and if ($errors[0]['SQLSTATE'] != '07006' and
$errors[0]['SQLSTATE'] != '22008' and
$errors[0]['SQLSTATE'] != '22007' and $errors[0]['SQLSTATE'] != '22007' and
$errors[0]['SQLSTATE'] != '07006') { $errors[0]['SQLSTATE'] != '22008' and
$errors[0]['SQLSTATE'] != '22018') {
print_r($errors); print_r($errors);
fatalError("Unexpected error"); fatalError("Unexpected error");
} }
@ -26,133 +30,156 @@ function ExecutePreparedStmt($stmt)
} }
// Compare dates retrieved from the database with the date used for testing. // Compare dates retrieved from the database with the date used for testing.
// $testingDate is an array of strings like '2002-01-31 23:59:59.049876' and // $expectedDateTime is an array of strings like '2002-01-31 23:59:59.049876'
// $retrieved_date is the string date of the format 'Y-m-d H:i:s.u', which // $retrievedDateTime is date/time string of format either 'Y-m-d H:i:s.u' or
// the format returned by the date_format() calls below or by retrieval as // 'Y-m-d H:i:s.u P', which is the format returned when $returnDatesAsStrings
// strings, unless $datetimetype is date or time. In that case, if // is true, or by the date_format() calls in FetchDatesAndOrTimes when a PHP
// $returnStrings is false and $datetimetype is 'date', the time defaults to // DateTime object is retrieved (i.e. when $returnDatesAsStrings is false),
// 00:00:00.0000, and if $datetimetype is 'time' and $returnStrings is false, // unless $datetimetype is date or time. In those cases:
// the date defaults to the current date. If however $returnStrings is true // If $datetimetype is date and $returnDatesAsStrings is false:
// and $datetimetype is 'date', $retrieved_date is only a date, // The date is as expected, the time defaults to 00:00:00.0000
// and if $datetimetype is 'time' and $returnStrings is true, $retrieved_date // If $datetimetype is time and $returnStrings is false:
// only a time. // The date defaults to the current date, the time is as expected.
// The concatenations involving zeroes below are to make direct string // If $datetimetype is date and $returnStrings is true:
// comparisons feasible. Also, because PHP maxes out at microsecond precision // $retrievedDateTime is only a date.
// and SQL Server maxes out at 0.1 microsecond precision, the more precise // If $datetimetype is 'time' and $returnStrings is true:
// types require an extra 0 for some comparisons. // $retrievedDateTime is only a time.
function CompareDateTime($datetimetype, $returnStrings, &$testingDate, $retrievedDate) function CompareDateTime($datetimetype, $returnStrings, &$expectedDateTime, $retrievedDateTime)
{ {
$test_date_time = array(); $expected_date_time = array();
for ($i=0; $i<sizeof($testingDate); ++$i) { // Split each element of the testing date/time into
$test_date_time[] = explode(" ", $testingDate[$i]); // [0]:date, [1]:time, and possibly [2]:timezone offset
for ($i=0; $i<sizeof($expectedDateTime); ++$i) {
$expected_date_time[] = explode(" ", $expectedDateTime[$i]);
} }
$ret_date_time = explode(" ", $retrievedDate); // If $retrievedDateTime is a string of format 'Y-m-d H:i:s.u' or 'Y-m-d H:i:s.u P',
if (sizeof($ret_date_time)>1) { // split it into [0]:date, [1]:time, and possibly [2]:timezone offset
$datetimeonly = $ret_date_time[0]." ".$ret_date_time[1]; $retrieved_date_time = explode(" ", $retrievedDateTime);
}
if (sizeof($ret_date_time)>2) {
$timezone = $ret_date_time[2];
$dtoffset = $ret_date_time[0]." ".substr($ret_date_time[1], 0, -1)." ".$ret_date_time[2];
}
if ($returnStrings == true) { if ($returnStrings == true) {
switch ($datetimetype) { switch ($datetimetype) {
case 'date': case 'date':
if ($retrievedDate != $test_date_time[0][0]) { // Direct comparison of retrieved date and expected date
if ($retrievedDateTime != $expected_date_time[0][0]) {
fatalError("Dates do not match!"); fatalError("Dates do not match!");
} }
break; break;
case 'time': case 'time':
if ($retrievedDate != $test_date_time[0][1]."0" and // Compare SQL time with expected time. The expected time was input
$retrievedDate != $test_date_time[1][1]."0" and // with an accuracy of microseconds and the SQL Servertime type has
$retrievedDate != $test_date_time[2][1]."0" and // accuracy to 100 ns, so times are returned with an extra zero. For
$retrievedDate != $test_date_time[3][1]."0" ) { // comparison the zero is appended to the times in expected_time_date.
if ($retrievedDateTime != $expected_date_time[0][1]."0" and
$retrievedDateTime != $expected_date_time[1][1]."0" and
$retrievedDateTime != $expected_date_time[2][1]."0" and
$retrievedDateTime != $expected_date_time[3][1]."0" ) {
fatalError("Times do not match!"); fatalError("Times do not match!");
} }
break; break;
case 'datetime': case 'datetime':
if ($retrievedDate."000" != $testingDate[0] and // Compare retrieved SQL datetime with expected date/time.
$retrievedDate."000" != $testingDate[1] and // SQL Server's datetime type is accurate to milliseconds and
$retrievedDate."000" != $testingDate[2] and // the expected time is accurate to microseconds, so append
$retrievedDate."000" != $testingDate[3] ) { // three zeroes to the retrieved time for comparison.
if ($retrievedDateTime."000" != $expectedDateTime[0] and
$retrievedDateTime."000" != $expectedDateTime[1] and
$retrievedDateTime."000" != $expectedDateTime[2] and
$retrievedDateTime."000" != $expectedDateTime[3] ) {
fatalError("Datetimes do not match!"); fatalError("Datetimes do not match!");
} }
break; break;
case 'datetime2': case 'datetime2':
if ($retrievedDate != $testingDate[0]."0" and // Compare retrieved SQL datetime2 with expected date/time.
$retrievedDate != $testingDate[1]."0" and // SQL Server's datetime2 type is accurate to 100 ns and
$retrievedDate != $testingDate[2]."0" and // the expected time is accurate to microseconds, so append
$retrievedDate != $testingDate[3]."0" ) { // a zero to the expected time for comparison.
if ($retrievedDateTime != $expectedDateTime[0]."0" and
$retrievedDateTime != $expectedDateTime[1]."0" and
$retrievedDateTime != $expectedDateTime[2]."0" and
$retrievedDateTime != $expectedDateTime[3]."0" ) {
fatalError("Datetime2s do not match!"); fatalError("Datetime2s do not match!");
} }
break; break;
case 'datetimeoffset': case 'datetimeoffset':
if ($dtoffset != $testingDate[4] and // Compare the SQL datetimeoffset retrieved with expected
$dtoffset != $testingDate[5] and // date/time. datetimeoffset is accurate to 100 ns, so the
$dtoffset != $testingDate[6] and // extra zero is removed in $dtoffset to create a format accurate
$dtoffset != $testingDate[7] ) { // to microseconds for comparison with the expected date/time/timezone.
$dtoffset = $retrieved_date_time[0]." ".substr($retrieved_date_time[1], 0, -1)." ".$retrieved_date_time[2];
if ($dtoffset != $expectedDateTime[4] and
$dtoffset != $expectedDateTime[5] and
$dtoffset != $expectedDateTime[6] and
$dtoffset != $expectedDateTime[7] ) {
fatalError("Datetimeoffsets do not match!"); fatalError("Datetimeoffsets do not match!");
} }
break; break;
case 'smalldatetime': case 'smalldatetime':
if ($retrievedDate.".000000" != $testingDate[0] and // Compare retrieved SQL smalldatetime with expected date/time.
$retrievedDate.".000000" != $testingDate[1] and // SQL Server's smalldatetime type is accurate to seconds and
$retrievedDate.".000000" != $testingDate[2] and // the expected time is accurate to microseconds, so append
$retrievedDate.".000000" != $testingDate[3] ) { // '.000000' to the expected time for comparison.
if ($retrievedDateTime.".000000" != $expectedDateTime[0] and
$retrievedDateTime.".000000" != $expectedDateTime[1] and
$retrievedDateTime.".000000" != $expectedDateTime[2] and
$retrievedDateTime.".000000" != $expectedDateTime[3] ) {
fatalError("Smalldatetimes do not match!"); fatalError("Smalldatetimes do not match!");
} }
break; break;
} }
} }
else { else {
// Combine the retrieved date and time.
if (sizeof($retrieved_date_time)>1) {
$date_time_only = $retrieved_date_time[0]." ".$retrieved_date_time[1];
}
// Times returned by SQL Server are accurate to 100 ns, but when
// formatted using PHP's date_format() function, the times are accurate
// to microseconds. So both retrieved and expected times are accurate
// to microseconds, and no need for adding zeroes in any of the
// comparisons below.
switch ($datetimetype) { switch ($datetimetype) {
case 'date': case 'date':
if ($ret_date_time[0] != $test_date_time[0][0]) { // Comparison of dates only.
if ($retrieved_date_time[0] != $expected_date_time[0][0]) {
fatalError("Dates do not match!"); fatalError("Dates do not match!");
} }
break; break;
case 'time': case 'time':
if ($ret_date_time[1] != $test_date_time[0][1] and // Comparison of times only.
$ret_date_time[1] != $test_date_time[1][1] and if ($retrieved_date_time[1] != $expected_date_time[0][1] and
$ret_date_time[1] != $test_date_time[2][1] and $retrieved_date_time[1] != $expected_date_time[1][1] and
$ret_date_time[1] != $test_date_time[3][1] ) { $retrieved_date_time[1] != $expected_date_time[2][1] and
$retrieved_date_time[1] != $expected_date_time[3][1] ) {
fatalError("Times do not match!"); fatalError("Times do not match!");
} }
break; break;
case 'datetime': case 'datetime':
if ($datetimeonly != $testingDate[0] and case 'datetime2':
$datetimeonly != $testingDate[1] and case 'smalldatetime':
$datetimeonly != $testingDate[2] and // Test combined date and time. The $expectedDateTime values
$datetimeonly != $testingDate[3] ) { // all have a different number of trailing zeroes to match
// the precision of different SQL types.
if ($date_time_only != $expectedDateTime[0] and
$date_time_only != $expectedDateTime[1] and
$date_time_only != $expectedDateTime[2] and
$date_time_only != $expectedDateTime[3] ) {
fatalError("Datetimes do not match!"); fatalError("Datetimes do not match!");
} }
break; break;
case 'datetime2':
if ($datetimeonly != $testingDate[0] and
$datetimeonly != $testingDate[1] and
$datetimeonly != $testingDate[2] and
$datetimeonly != $testingDate[3] ) {
fatalError("Datetime2s do not match!");
}
break;
case 'datetimeoffset': case 'datetimeoffset':
if ($retrievedDate != $testingDate[4] and // The retrieved date/time string will have a timezone
$retrievedDate != $testingDate[5] and // correction appended to it when the returned type is
$retrievedDate != $testingDate[6] and // datetimeoffset.
$retrievedDate != $testingDate[7] ) { if ($retrievedDateTime != $expectedDateTime[4] and
$retrievedDateTime != $expectedDateTime[5] and
$retrievedDateTime != $expectedDateTime[6] and
$retrievedDateTime != $expectedDateTime[7] ) {
fatalError("Datetimeoffsets do not match!"); fatalError("Datetimeoffsets do not match!");
} }
break; break;
case 'smalldatetime':
if ($datetimeonly != $testingDate[0] and
$datetimeonly != $testingDate[1] and
$datetimeonly != $testingDate[2] and
$datetimeonly != $testingDate[3] ) {
fatalError("Smalldatetimes do not match!");
}
break;
} }
} }
} }
@ -168,8 +195,7 @@ function InsertDatesAndOrTimes($conn, $datetimetype, &$formats_array, $array_siz
} }
$insertSql = "INSERT INTO [$tableName] (id, [c1_$datetimetype]) VALUES (?, ?)"; $insertSql = "INSERT INTO [$tableName] (id, [c1_$datetimetype]) VALUES (?, ?)";
for ($i=0; $i<$array_size; $i++) for ($i=0; $i<$array_size; $i++) {
{
$stmt = sqlsrv_prepare($conn, $insertSql, array($i, array($formats_array[$i], SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'), $SQLSRV_SQLTYPE_CONST))); $stmt = sqlsrv_prepare($conn, $insertSql, array($i, array($formats_array[$i], SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'), $SQLSRV_SQLTYPE_CONST)));
ExecutePreparedStmt($stmt); ExecutePreparedStmt($stmt);
$stmt = sqlsrv_prepare($conn, $insertSql, array($i, $formats_array[$i])); $stmt = sqlsrv_prepare($conn, $insertSql, array($i, $formats_array[$i]));
@ -186,7 +212,7 @@ function InsertDatesAndOrTimes($conn, $datetimetype, &$formats_array, $array_siz
} }
} }
function FetchDatesAndOrTimes($conn, $datetimetype, &$testingDate, $returnDatesAsStrings) function FetchDatesAndOrTimes($conn, $datetimetype, &$expectedDateTime, $returnDatesAsStrings)
{ {
$tableName = "table_of_$datetimetype"; $tableName = "table_of_$datetimetype";
@ -205,10 +231,11 @@ function FetchDatesAndOrTimes($conn, $datetimetype, &$testingDate, $returnDatesA
fatalError("sqlsrv_get_field did not return string but string was specified"); fatalError("sqlsrv_get_field did not return string but string was specified");
} }
CompareDateTime($datetimetype, true, $testingDate, $datetime); CompareDateTime($datetimetype, true, $expectedDateTime, $datetime);
} }
// retrieve date time fields as DateTime objects // retrieve date time fields as DateTime objects
// format them as strings using date_format() for comparison
echo "Select fields as DateTime objects:\n"; echo "Select fields as DateTime objects:\n";
$stmt = sqlsrv_query($conn, "SELECT * FROM [$tableName]"); $stmt = sqlsrv_query($conn, "SELECT * FROM [$tableName]");
@ -226,7 +253,7 @@ function FetchDatesAndOrTimes($conn, $datetimetype, &$testingDate, $returnDatesA
$datetime = ($datetimetype == 'datetimeoffset') ? date_format($datetime, 'Y-m-d H:i:s.u P') : date_format($datetime, 'Y-m-d H:i:s.u'); $datetime = ($datetimetype == 'datetimeoffset') ? date_format($datetime, 'Y-m-d H:i:s.u P') : date_format($datetime, 'Y-m-d H:i:s.u');
CompareDateTime($datetimetype, false, $testingDate, $datetime); CompareDateTime($datetimetype, false, $expectedDateTime, $datetime);
} }
// retrieve date time fields without explicitly requesting the type // retrieve date time fields without explicitly requesting the type
@ -246,7 +273,7 @@ function FetchDatesAndOrTimes($conn, $datetimetype, &$testingDate, $returnDatesA
fatalError("String for date expected, not a string"); fatalError("String for date expected, not a string");
} }
CompareDateTime($datetimetype, $returnDatesAsStrings, $testingDate, $datetime); CompareDateTime($datetimetype, $returnDatesAsStrings, $expectedDateTime, $datetime);
} }
else { // ReturnsDatesAsStrings is false else { // ReturnsDatesAsStrings is false
if (!($datetime instanceof DateTime)) { if (!($datetime instanceof DateTime)) {
@ -255,7 +282,7 @@ function FetchDatesAndOrTimes($conn, $datetimetype, &$testingDate, $returnDatesA
$datetime = ($datetimetype == 'datetimeoffset') ? date_format($datetime, 'Y-m-d H:i:s.u P') : date_format($datetime, 'Y-m-d H:i:s.u'); $datetime = ($datetimetype == 'datetimeoffset') ? date_format($datetime, 'Y-m-d H:i:s.u P') : date_format($datetime, 'Y-m-d H:i:s.u');
CompareDateTime($datetimetype, $returnDatesAsStrings, $testingDate, $datetime); CompareDateTime($datetimetype, $returnDatesAsStrings, $expectedDateTime, $datetime);
} }
} }
@ -275,7 +302,7 @@ function FetchDatesAndOrTimes($conn, $datetimetype, &$testingDate, $returnDatesA
fatalError("String for date expected, not a string"); fatalError("String for date expected, not a string");
} }
CompareDateTime($datetimetype, $returnDatesAsStrings, $testingDate, $row[1]); CompareDateTime($datetimetype, $returnDatesAsStrings, $expectedDateTime, $row[1]);
} }
else { else {
if (!($row[1] instanceof DateTime)) { if (!($row[1] instanceof DateTime)) {
@ -284,7 +311,7 @@ function FetchDatesAndOrTimes($conn, $datetimetype, &$testingDate, $returnDatesA
$datetime = ($datetimetype == 'datetimeoffset') ? date_format($row[1], 'Y-m-d H:i:s.u P') : date_format($row[1], 'Y-m-d H:i:s.u'); $datetime = ($datetimetype == 'datetimeoffset') ? date_format($row[1], 'Y-m-d H:i:s.u P') : date_format($row[1], 'Y-m-d H:i:s.u');
CompareDateTime($datetimetype, $returnDatesAsStrings, $testingDate, $datetime); CompareDateTime($datetimetype, $returnDatesAsStrings, $expectedDateTime, $datetime);
} }
} }
@ -313,15 +340,21 @@ $frac = '04';
$frac2 = '9876'; $frac2 = '9876';
$tz_correction = '+08:00'; $tz_correction = '+08:00';
$testingDate = array($year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".".$frac.$frac2, // This is the array of dates/times/timezones to test against. They have
$year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".".$frac."0000", // different numbers of trailing zeroes to match the precision of different
$year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".000000", // SQL date and time types, but all go up to microseconds because that's
$year."-".$month."-".$day." ".$hour.":".$minute.":00.000000", // how PHP formats times with date_format(), allowing direct string comparisons
$year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".".$frac.$frac2." ".$tz_correction, // when the DateTime objects retrieved from a table are formatted as strings
$year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".".$frac."0000 ".$tz_correction, // with date_format().
$year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".000000 ".$tz_correction, $expectedDateTime = array($year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".".$frac.$frac2,
$year."-".$month."-".$day." ".$hour.":".$minute.":00.000000 ".$tz_correction, $year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".".$frac."0000",
); $year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".000000",
$year."-".$month."-".$day." ".$hour.":".$minute.":00.000000",
$year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".".$frac.$frac2." ".$tz_correction,
$year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".".$frac."0000 ".$tz_correction,
$year."-".$month."-".$day." ".$hour.":".$minute.":".$second.".000000 ".$tz_correction,
$year."-".$month."-".$day." ".$hour.":".$minute.":00.000000 ".$tz_correction,
);
// These formats are for the ODBC driver with types specified in sqlsrv_prepare() // These formats are for the ODBC driver with types specified in sqlsrv_prepare()
$date_formats = array($year."-".$month."-".$day $date_formats = array($year."-".$month."-".$day
@ -365,12 +398,14 @@ $SZ_TIME_all = sizeof($time_formats_all);
$SZ_DATE_all = sizeof($date_formats_all); $SZ_DATE_all = sizeof($date_formats_all);
$SZ_DATETIME_all = $SZ_TIME_all*$SZ_DATE_all; $SZ_DATETIME_all = $SZ_TIME_all*$SZ_DATE_all;
// Create compound date/time types. For datetime, remove the extra precision // Create compound date/time/timezone arrays corresponding to the SQL Server
// of $frac2. For smalldatetime, remove the extra precision of $frac and $frac2. // date/time types by concatenating the dates and times from above. For the
// If the data in $frac and/or $frac2 is found elsewhere in the date/time, the // datetime type, remove the extra precision of $frac2. For the smalldatetime
// data will be garbled. For example, if the year is 2002 and $frac2 is 2002, // type, remove the extra precision of $frac and $frac2. If the numerical
// the code below will remove any instances of '2002' in the datetime and // string in $frac and/or $frac2 is found elsewhere in the date/time, the data
// smalldatetime strings, producing garbage for those types. User must be // will be garbled. For example, if the year is 2002 and $frac2 is 2002, the
// code below will remove any instances of '2002' in the datetime and
// smalldatetime strings, producing garbage for those types. User must be
// cognizant of this when testing different dates and times. // cognizant of this when testing different dates and times.
for ($i=0; $i<$SZ_DATE_all; $i++) for ($i=0; $i<$SZ_DATE_all; $i++)
{ {
@ -406,12 +441,12 @@ InsertDatesAndOrTimes($conn, 'datetime2', $datetime2_formats_all, $SZ_DATETIME_a
InsertDatesAndOrTimes($conn, 'datetimeoffset', $datetimeoffset_formats_all, $SZ_DATETIME_all, SQLSRV_SQLTYPE_DATETIMEOFFSET); InsertDatesAndOrTimes($conn, 'datetimeoffset', $datetimeoffset_formats_all, $SZ_DATETIME_all, SQLSRV_SQLTYPE_DATETIMEOFFSET);
InsertDatesAndOrTimes($conn, 'smalldatetime', $datetimesmall_formats_all, $SZ_DATETIME_all, SQLSRV_SQLTYPE_SMALLDATETIME); InsertDatesAndOrTimes($conn, 'smalldatetime', $datetimesmall_formats_all, $SZ_DATETIME_all, SQLSRV_SQLTYPE_SMALLDATETIME);
FetchDatesAndOrTimes($conn, 'date', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'date', $expectedDateTime, $returnDatesAsStrings);
FetchDatesAndOrTimes($conn, 'time', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'time', $expectedDateTime, $returnDatesAsStrings);
FetchDatesAndOrTimes($conn, 'datetime', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'datetime', $expectedDateTime, $returnDatesAsStrings);
FetchDatesAndOrTimes($conn, 'datetime2', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'datetime2', $expectedDateTime, $returnDatesAsStrings);
FetchDatesAndOrTimes($conn, 'datetimeoffset', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'datetimeoffset', $expectedDateTime, $returnDatesAsStrings);
FetchDatesAndOrTimes($conn, 'smalldatetime', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'smalldatetime', $expectedDateTime, $returnDatesAsStrings);
sqlsrv_close($conn); sqlsrv_close($conn);
@ -426,12 +461,12 @@ InsertDatesAndOrTimes($conn, 'datetime2', $datetime2_formats_all, $SZ_DATETIME_a
InsertDatesAndOrTimes($conn, 'datetimeoffset', $datetimeoffset_formats_all, $SZ_DATETIME_all, SQLSRV_SQLTYPE_DATETIMEOFFSET); InsertDatesAndOrTimes($conn, 'datetimeoffset', $datetimeoffset_formats_all, $SZ_DATETIME_all, SQLSRV_SQLTYPE_DATETIMEOFFSET);
InsertDatesAndOrTimes($conn, 'smalldatetime', $datetimesmall_formats_all, $SZ_DATETIME_all, SQLSRV_SQLTYPE_SMALLDATETIME); InsertDatesAndOrTimes($conn, 'smalldatetime', $datetimesmall_formats_all, $SZ_DATETIME_all, SQLSRV_SQLTYPE_SMALLDATETIME);
FetchDatesAndOrTimes($conn, 'date', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'date', $expectedDateTime, $returnDatesAsStrings);
FetchDatesAndOrTimes($conn, 'time', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'time', $expectedDateTime, $returnDatesAsStrings);
FetchDatesAndOrTimes($conn, 'datetime', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'datetime', $expectedDateTime, $returnDatesAsStrings);
FetchDatesAndOrTimes($conn, 'datetime2', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'datetime2', $expectedDateTime, $returnDatesAsStrings);
FetchDatesAndOrTimes($conn, 'datetimeoffset', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'datetimeoffset', $expectedDateTime, $returnDatesAsStrings);
FetchDatesAndOrTimes($conn, 'smalldatetime', $testingDate, $returnDatesAsStrings); FetchDatesAndOrTimes($conn, 'smalldatetime', $expectedDateTime, $returnDatesAsStrings);
sqlsrv_close($conn); sqlsrv_close($conn);