Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't display null date fields

Status
Not open for further replies.

combs

Programmer
Joined
Apr 18, 2002
Messages
78
Location
US
Hi,

I'm pulling information from an Access Database to display on the internet. I have several date fields in the database that may or may not contain dates. When there are no dates I would like the field (in the table) to just be blank. However, I keep getting errors like the following when I encounter blank fields:

Warning: Unsupported variant type: 1 (0x1) in D:\Inetpub\billings\pwe\employee\php_test\display_pci.php on line 156

Several text and integer fields work great. Just a problem with the [blank] date fields.


I have tried to test to see if the field is null (is_null()) and that doesn't seem to work. I have tried to test the length of the field (strlen()) to see if it's shorter than a valid length and can't seem to get that working either. I would really appreciate any help anyone can offer as to how to get the blank entries to display w/o the error messages.


Here is how I connect to the database:
//============================
//Open Database Connection
//============================
$db = 'D:\Inetpub\billings\pwe\data\pwe1.mdb';
$conn = new COM('ADODB.Connection');
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");



$SQL = "SELECT * FROM [2004_PCI] WHERE [2004_PCI].Name = '".$StrStreetName."'";

//=====================
// FOR DE-BUGGING
//=====================
//echo $SQL.&quot;<BR>&quot;;

$rs = $conn->Execute($SQL);

if ($rs->EOF)
{
$rs.Close();
$conn.Close();
//Response.Redirect(&quot;SelectStreet.asp?Error=yes&quot;)
//Response.End
}
else
{
$rs->MoveFirst();
}

And then when I want to display the info:

<? while (!$rs->EOF)
{
?>
<tr>
<td width=&quot;135&quot; bgcolor=&quot;#CCFFFF&quot;>
<font face=&quot;Arial&quot; size=&quot;1&quot;>
<? $StrName = $rs->Fields['Name']->value;
$StrSec = $rs->Fields['Sec #']->value;
$StrFrom = substr($rs->Fields['From']->value,0,2);
echo &quot;<a target='_blank' href='WorkHistory.asp?name=&quot;.$StrName.&quot;&sec=&quot;.$StrSec.&quot;&from=&quot;.$StrFrom.&quot;'>&quot;.$StrName.&quot;</a>&quot;; ?>
</font>
</td>
<td width=&quot;31&quot; bgcolor=&quot;#CCFFFF&quot; align=&quot;center&quot;>
<font face=&quot;Arial&quot; size=&quot;1&quot;>
<?$StrTemp = $rs->Fields['Zone']->value;
if (substr($StrTemp,0,2) == &quot;nm&quot;) { ?>
<font color=&quot;#FF0000&quot;>
<? echo $HREFString.$JavaString.$StrTemp.&quot;</A>&quot;; ?>
</font>
<? }Else {
echo $StrTemp;
} ?>
</font>
</td>
<td width=&quot;164&quot; bgcolor=&quot;#CCFFFF&quot;>
<font face=&quot;Arial&quot; size=&quot;1&quot;>
<?= $rs->Fields['From']->value ?>
</font>
</td>
<td width=&quot;152&quot; bgcolor=&quot;#CCFFFF&quot;>
<font face=&quot;Arial&quot; size=&quot;1&quot;>
<?= $rs->Fields['To']->value ?>
</font>
</td>
<td width=&quot;33&quot; align=&quot;center&quot; bgcolor=&quot;#CCFFFF&quot;>
<font face=&quot;Arial&quot; size=&quot;1&quot;>
<?= $rs->Fields['Width']->value ?>
</font>
</td>
<td width=&quot;89&quot; align=&quot;center&quot; bgcolor=&quot;#CCFFFF&quot;>
<font face=&quot;Arial&quot; size=&quot;1&quot;>
<?
if ($rs->Fields['Last Constructed']->value < strtotime(&quot;1/1/1970&quot;))
{
print &quot;<font color='#FF0000'>1/1/1960</font>&quot;;
}
else
{
print date(&quot;m/d/Y&quot;,$rs->Fields['Last Constructed']->value);
}
//date(&quot;m/d/Y&quot;,$rs->Fields['Last Constructed']->value) ?>
</font>
</td>
<td width=&quot;49&quot; align=&quot;center&quot; bgcolor=&quot;#CCFFFF&quot;>
<font face=&quot;Arial&quot; size=&quot;1&quot;>
<?
if ($rs->Fields['Last Inspected']->value < strtotime(&quot;1/1/1970&quot;))
{
print &quot;<font color='#FF0000'>1/1/1960</font>&quot;;
}
else
{
print date(&quot;m/d/Y&quot;,$rs->Fields['Last Inspected']->value);
}
//date(&quot;m/d/Y&quot;,$rs->Fields['Last Inspected']->value) ?>
</font>
</td>
<td width=&quot;30&quot; align=&quot;center&quot; bgcolor=&quot;#CCFFCC&quot;>
<font face=&quot;Arial&quot; size=&quot;1&quot;>
<?= $rs->Fields['Last PCI']->value ?>
</font>
</td>
<td width=&quot;25&quot; align=&quot;center&quot; bgcolor=&quot;#CCFFFF&quot;>
<font face=&quot;Arial&quot; size=&quot;1&quot;>
<? $temp = $rs->Fields['Last Chip Seal'];
if ($temp->value < strtotime(&quot;1/1/1970&quot;))
{
print &quot;<font color='#FF0000'>1960</font>&quot;;
}
else
{
print date(&quot;Y&quot;,$temp->value);
}
/*
if (is_long($rs->Fields['Last Chip Seal']))
{
print &quot;<font color='#FF0000'>N/A</font>&quot;;
}
else
{
print date(&quot;Y&quot;,$rs->Fields['Last Chip Seal']->value);
} */
?>
</font>
</td>
<td width=&quot;41&quot; align=&quot;center&quot; bgcolor=&quot;#CCFFFF&quot;>
<font face=&quot;Arial&quot; size=&quot;1&quot;>
<? $StrTemp = $rs->Fields['Surface Type']->value;
if ($StrTemp == &quot;GR&quot;) { ?>
<font color=&quot;#FF0000&quot;><b>
<? echo $HREFString.$JavaString2.$StrTemp.&quot;</A>&quot;; ?>
</b></font>
<? } else {
echo $StrTemp;
} ?>
</font>
</td>
</tr>
<? $rs->MoveNext();
}

$rs->Close();
$conn->Close();
?>
<tr>
The &quot;Last Chip Seal&quot; date is the one that I have problems with. The &quot;Last Constructed&quot; and &quot;Last Inspected&quot; dates seeem to work fine - there are no blank or null entries in these fields.

Thanks in advance for your help!
 
I use this function for the 'empty' time fields

Code:
function tijd($tijdvar){
$temptijd=strftime('%H:%M',strtotime($tijdvar));
if ($temptijd == &quot;00:00&quot;) {return &quot;&quot;;}
	else 
	{return $temptijd;}

}

perhaps you can also use it for the date problem
 
Thanks for your response hos2.

I tried your function and it seems to work, but it doesn't help me (if I'm using it correctly...) I just get blank cells in my table. (Even when there is data...)

My main problem is that I can't get/retrieve the value when it's null - I get an error message:

I can do this: (with no error message)

<? $temp = $rs->Fields['Last Chip Seal'];
$temp = tijd($temp);
print &quot;$temp&quot;;
?>

but when I do this, I get an error message:

<? $temp = $rs->Fields['Last Chip Seal']->value;
$temp = tijd($temp);
print &quot;$temp&quot;;
?>


Basically anytime I attach the &quot;->value&quot; when the value is null I get the error message. Is there anyway to test for null w/o the ->value extension being used??

Thanks again,
Damon
 
normally a date value is not null but 0000-00-00

perhaps you can build in a check for the year with a if function and you only accept years above 1900
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top