Copy only dates

Posted on 2016-09-18
Last Modified: 2016-09-18
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 

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 ?
Question by:amucinobluedot
  • 2
LVL 23

Expert Comment

by:Pawan Kumar
ID: 41804131
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
LVL 23

Accepted Solution

Pawan Kumar earned 500 total points
ID: 41804134
If above dont work then you write 2 statements


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

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


Open in new window


Author Closing Comment

ID: 41804146

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Parse field in SQL View 15 96
SQL Query stumper 3 36
tag title an image 13 13
Help Extract Specific in SQL 8 15
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now