Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert Date mm/dd/yyyy in to yyyymmdd

Author  Topic 

archana23
Yak Posting Veteran

89 Posts

Posted - 2013-10-22 : 15:50:21
Hi,

How can i convert date which is in mm/dd/yyyy format to yyyymmdd.

I have input parameter called JoinDate = '09/26/2013'

I need to convert this as '20130926' .

Can any one please help me on this?

Thank you.

Archana

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-10-22 : 15:55:41
Please take a look at the CONVERT function. There are styles available to convert date/time data to different formats.

But this is a presentation issue and should not be done inside T-SQL. Let the application layer handle any formatting.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-23 : 02:01:52
date which is in mm/dd/yyyy
this suggests you're not using datetime as datatype for storing dates. Please use proper datatypes for storing date values.
Then whatever format you want you can convert them using CONVERT function.
As suggested I would also suggest to do this at front end if possible.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

archana23
Yak Posting Veteran

89 Posts

Posted - 2013-10-23 : 14:23:01
I need to this Conversion from mm/dd/yyyy to yyyymmdd in SQL Server stored procedure itself.

How can we do this in SQL Server?


Archana
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-23 : 14:27:47
Like shown below:
SET DATEFORMAT MDY;
DECLARE @joindate VARCHAR(32) = '09/26/2013';
SELECT CONVERT(CHAR(8),CAST(@joindate AS DATETIME),112)
Go to Top of Page

archana23
Yak Posting Veteran

89 Posts

Posted - 2013-10-23 : 15:29:51
Thank you James. It worked.

Archana
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-23 : 16:36:32
Great! Glad to be of help.
Go to Top of Page
   

- Advertisement -