SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert Date mm/dd/yyyy in to yyyymmdd
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

archana23
Yak Posting Veteran

74 Posts

Posted - 10/22/2013 :  15:50:21  Show Profile  Reply with Quote
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

USA
36653 Posts

Posted - 10/22/2013 :  15:55:41  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

India
52309 Posts

Posted - 10/23/2013 :  02:01:52  Show Profile  Reply with Quote
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

74 Posts

Posted - 10/23/2013 :  14:23:01  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3568 Posts

Posted - 10/23/2013 :  14:27:47  Show Profile  Reply with Quote
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

74 Posts

Posted - 10/23/2013 :  15:29:51  Show Profile  Reply with Quote
Thank you James. It worked.

Archana
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3568 Posts

Posted - 10/23/2013 :  16:36:32  Show Profile  Reply with Quote
Great! Glad to be of help.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000