[thelist] is_null php
rudy
rudy937 at rogers.com
Tue Jul 29 19:31:51 CDT 2003
> I have a NULL date value in my mySQL table. I want to test and see
> whether it has a date or its null, a simple if condition. If it is
> not null, i want to print out a variable.
you mean the other way around? when it's null, print something?
testing for nulls is best done by the database
(so are other things related to date handling, simon, but i shall not take
you up on this at this time)
for an interesting read, look up the coalesce() function in mysql, and
picture it with more than two parameters...
tom, why don't you just return the result as a string, if all you want is to
print it?
select
case when thedate is null
then 'no date'
else date_format(thedate,'%Y-%m-%d')
end as prtdate
from ...
aside from minor differences between date formatting functions across
databases (e.g. in sql server it's the convert() function, with different
parameters), this is the most portable strategy, as it makes your script
logic trivial, you just display the prtdate column as a string
as for your other question, "what if I accidentally get a space in that
field?" -- that couldn't possibly happen if you are using a date or datetime
datatype to store the date
rudy
More information about the thelist
mailing list