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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to compare a date to a null

Status
Not open for further replies.

mtbcoach

Programmer
Feb 11, 2001
9
CA
hi,

i would like to know how to compare a date format to a null. I have tried ISNULL and = "" but the error is that the format do not match.

Thank you for your time

Mathieu G.
 
Some context (code) on how you are currently trying it would be helpful, but isNull is probably what you are looking for:

if not isNull(theDate) then
'something
else
'something else
end if
penny.gif
penny.gif
 
Suppose that depends on what language you're using etc... I've had some success working with the Julian format for dates... basically the Julian form of a date is the number of days since March 1, 1900, and null dates have Julians of 0. There are lots of resources online to find the formula for Julian... just run a search for it. :)

SheRa M&M's are better than money because you can eat them. ;)
 
JavaScript --
Code:
if(theDate == null || theDate == "" || theDate.length == 0 || theDate == "null"){
   proceed without theDate;
}else {
   proceed to use theDate;
}


T-SQL --
Code:
DECLARE @theDate DATETIME
SELECT @theDate = (SELECT begin_date FROM tableOne WHERE some_id = 'some_id_value')

SELECT @theDate

IF @theDate IS NULL
BEGIN
   SELECT @theDate
END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top