Date format - SQL Query

Abdul Khan
Abdul Khan used Ask the Experts™
on
How do I remove the slashes '/' from the date field, here's what I have:

CONVERT(varchar, aam.orderStatusDateField, 101)       

and this is what prints:  '02/14/2018'  

I need to print :  '02142018'
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Scott PletcherSenior DBA
Most Valuable Expert 2018
Top Expert 2014

Commented:
REPLACE(CONVERT(varchar(10), aam.orderStatusDateField, 101) , '/', '')
Analyst Assistant
Commented:
Try this.

REPLACE(CONVERT(varchar, aam.orderStatusDateField, 101), '/', '')
PortletPaulEE Topic Advisor
Most Valuable Expert 2014
Awarded 2013

Commented:
If you are running SQL Server 2012 or later you can use FORMAT() which is much more intuitive

     format(aam.orderStatusDateField,'ddMMyyyy')
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
@Paul, thanks for the introducing Format() for date format, how do I combine it with CONVERT ; so essentially what would be the code for this using format()?

REPLACE(CONVERT(varchar, aam.orderStatusDateField, 101), '/', '')

Author

Commented:
@Paul Never mind, I got it. Thanks.
PortletPaulEE Topic Advisor
Most Valuable Expert 2014
Awarded 2013

Commented:
for the record: don't use convert..... just use format directly against the timestamp data, the returned value is a string

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial