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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 select dd/mm/yyyy as yyymmdd
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

esthera
Flowing Fount of Yak Knowledge

1388 Posts

Posted - 10/14/2012 :  06:13:28  Show Profile  Reply with Quote
I have a date like 13/09/2012 to yyyymmdd

How can i convert this so I can do calculations on the date using datediff

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/14/2012 :  10:12:24  Show Profile  Reply with Quote
If the data is stored as a datetime type (date, datetime, smalldatetime etc.), you wouldn't need to do any conversion. If it is stored as character (char, varchar etc.), use convert as in:
CONVERT(DATETIME,YourCol,103);
For Example:
DECLARE @x VARCHAR(32) = '13/09/2012';
SELECT CONVERT(DATETIME,@x,103);
SELECT DATEDIFF(dd,CONVERT(DATETIME,@x,103),GETDATE());
Here, I am not specifically converting it to yyyymmdd format. There is no need to because it is best to provide the parameters to DATEDIFF function in its required format - which is datetime.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 10/16/2012 :  09:45:04  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Always use proper DATETIME datatype to store datetime values and leave format at front end application

Madhivanan

Failing to plan is Planning to fail
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.05 seconds. Powered By: Snitz Forums 2000