Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Conversion 2

Status
Not open for further replies.

Rob7

Programmer
Dec 12, 2001
152
US
I have a date in the form of a datetime data type in a filed in sql (MM/DD/YYYY) and I want to put it in the form of yyyymmdd as an integer. Is there an easy way to do this with a sql statement in query analyzer?

Cytec Corporation
rbrown@cyteccorp.com
 

select 10000*datepart(year,getdate())+100*datepart(month,getdate())+datepart(day,getdate())

Mike Krausnick
Dublin, California
 
This might also work..

SELECT CONVERT(INTEGER,CONVERT(VARCHAR, getDate(),112))

-Kris
 
Well, the only problem is that the dates are already in the fields. Won't the getdate pull the system date? I want to convert existing data.

Cytec Corporation
rbrown@cyteccorp.com
 
Modify Kris11 and replace getdate() with your dat column

"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
That worked MDXer. I had to update to a new column but I can fix that part. Thanks everybody.

Cytec Corporation
rbrown@cyteccorp.com
 
The thanks should primarily go to Kris11

"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top