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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting DateTime Field to MMddyy Format? 2

Status
Not open for further replies.

SeaninSeattle

IS-IT--Management
Sep 17, 2001
53
US
Anyone know if an easy way to convert a datetime field to a MMddyy format? Thanks for your help! :)

Sean Engle
Admin/DirIS
ssengle@bswusa.com
 
Actually, I know about using the style setting:

select CONVERT(VARCHAR(25),GETDATE(),1)

gives:

06/03/03

But I need it without the whacks. Any ideas....anyone...I'm getting desperate here..... :)

//sse

Sean Engle
Admin/DirIS
ssengle@bswusa.com
 
Check out REPLACE in the BOL.

Here's what you want:

SELECT REPLACE(CONVERT(VARCHAR(8), GETDATE(), 1), '/', '')

You can replace GETDATE() with your datetime column.

-SQLBill
 
Oh God - I completely forgot about REPLACE... Never mind - thanks for help, though! :)

//sse

Sean Engle
Admin/DirIS
ssengle@bswusa.com
 
That's ok. I don't use it alot myself. Whenever I read about a command that I think might come in handy I write it down on my white-board. That's how I came up with the REPLACE command. Saw someone suggest it in a post, read about it, and posted it on my white-board under Handy TSQL commands.

-SQLBill
 
SeaninSeattle - I've been looking for a way to easily drop the timestamp from a datatime field. Thank you:)

Jason Meckley
Database Analyst
WITF
 
Depending on what you're trying to accomplish - I would just do a convert as mentioned above -

select CONVERT(VARCHAR(25),GETDATE(),1)


If you go to BOL, and look up 'CAST and CONVERT' you'll see a nice table of all the date/time styles - it's how I got to this point - not mentioning being forgetful as mentioned above... :)

//sse

Sean Engle
Admin/DirIS
ssengle@bswusa.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top