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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 select dd/mm/yyyy as yyymmdd
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Flowing Fount of Yak Knowledge

1410 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

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:
For Example:
DECLARE @x VARCHAR(32) = '13/09/2012';
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

Premature Yak Congratulator

22864 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


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000