tsql - Converting SQL date formats not ending up the same -


i trying remove timestamp date values end mm/dd/yy or mm/dd/yyyy. referenced many technet, stackoverflow, , w3schools articles still can't date appear correctly. of columns in table defined datetime , come same table.

i using convert statements this: convert(varchar(10), e.pd_dt, 101) 'paid date'

in place of 101 have used 10 , 11, still have same issue data (below). what's happening when date value (not including time) 8 characters, getting additional character time, seen in claim adjustment date-10 , claim adjustment date-11 columns. here data:

claim paid date-101     claim paid date     claim adjustment date-10    claim adjustment date-11    claim adjustment date 10/23/2012              10/23/12 12:00   9/4/2012 1                  9/4/2012 1                      9/4/12 12:00 10/23/2012              10/23/12 12:00   9/4/2012 1                  9/4/2012 1                      9/4/12 12:00 10/23/2012              10/23/12 12:00   9/4/2012 1                  9/4/2012 1                      9/4/12 12:00 09/06/2011              09/06/11 12:00   9/4/2012 1                  9/4/2012 1                      9/4/12 12:00 10/23/2012              10/23/12 12:00   8/21/2012                   8/21/2012                       8/21/12 12:00 09/06/2011              09/06/11 12:00   8/21/2012                   8/21/2012                       8/21/12 12:00 

the strange thing of dates in "claim paid date" column have 0 padding if month or day < 10. makes convert come out fine month or day < 10 , doens't have 0 problem.

you have string source, not datetime source.

what happens datetime:

select getdate() -- datetime       ,cast(getdate() date) --date       ,convert(varchar(10),getdate(),101) --101 format 

result:

datetime                date       101 format ----------------------- ---------- ---------- 2013-09-24 13:58:48.880 2013-09-24 09/24/2013 

what happens strings parading datetime:

declare @fake_date varchar(25) = '10/23/12 12:00 am' select cast(@fake_date datetime) --datetime       ,cast(@fake_date date) --date       ,convert(varchar(10),@fake_date,101) --101 format 

result:

datetime                date       101 format ----------------------- ---------- ---------- 2012-10-23 00:00:00.000 2012-10-23 10/23/12 1 

so perhaps want:

convert(varchar(10),cast(@fake_date date),101)  

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -