We help IT Professionals succeed at work.

How to check date is not dbnull

anusdesai
anusdesai asked
on
Hi,
I have a table with field type:datetime...
i retrieve its value from database
now if the date is null the value returned from database contains time and no date...if i check against
dbnull function it returns true even if the date is null as the field format is date and the value contains time ...how do i check for null date.


Regards.
Comment
Watch Question

very simple while fetching the datetime column name, covert that column to have just date and not time like below

select convert(datetime, COLUMNNAME, 101) from TABLENAME and check with either dbNull or "" (blank)
Top Expert 2008

Commented:
use isnull(mydate)
sorry try using this

select convert(varchar(10), COLUMNNAME, 101) FROM TABLENAME

Author

Commented:
Hi asvforce,
Cant change the query....can i check on the result
Yes by using the Format function on the resulting field you can do that, just try fetching "m/dd/yyyy" and if its blank or "1/1/1900" that means there is no date.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.