Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

Copy only dates

I am trying to make NULL fields that are not dates, date should only be either:

mm/dd/yyyy  OR mm/dd/yy

Anything that is not that format should be made NULL

Here is my current sql

UPDATE  dbo.Dependents SET DepLastUSEntry = NULL 
WHERE ISDATE(DepLastUSEntry)= 0

Open in new window


It is not making some of the fields NULL not sure why.  Perhaps it is allowing some 'dates' that are not in the format above, is there a way to check that it IS in the format as listed above ?
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Here you go

--

UPDATE  dbo.Dependents SET DepLastUSEntry = NULL 
WHERE ISDATE(FORMAT(DepLastUSEntry,'mm/dd/yyyy'))= 0

--

Open in new window


Pls let me know if you face any issues
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Thanks!