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

Author  Topic 

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2009-01-18 : 22:04:53
I am trying to convert a date to a number, I know I need to add a convert statement to my query. How do I do it?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-18 : 22:19:29
If you just want to convert it to a number as in 20080118 then you can use the cast or convert functions. But if you intend to do a calculation on it, such as converting it to Java time, then we'd need to know that. How do you intend to use the converted number?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-18 : 22:40:44
SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') AS [MMDDYYYY]

SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 103), '/', '') AS [DDMMYYYY]

Jai Krishna
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-18 : 22:42:52
quote:
Originally posted by Jai Krishna

SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') AS [MMDDYYYY]

SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 103), '/', '') AS [DDMMYYYY]

Jai Krishna


how do you think this will give you a number?
Go to Top of Page
   

- Advertisement -