Solved

Copy only dates

Posted on 2016-09-18
3
88 Views
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 
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 ?
0
Comment
Question by:amucinobluedot
  • 2
3 Comments
 
LVL 28

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
0
 
LVL 28

Accepted Solution

by:
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

0
 

Author Closing Comment

by:amucinobluedot
ID: 41804146
Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

770 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