Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
Convert DateTime to MMDDYY
Convert DateTime to MMDDYY
Rate Topic
Display Mode
Topic Options
Author
Message
pgatte
pgatte
Posted Thursday, January 07, 2010 11:05 AM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, July 05, 2011 2:47 PM
Points: 3,
Visits: 101
I am new to SQL.
Can you tell me how I would convert a DateTime field to MMDDYY without any / or .
Example I would need the field to convert to 10409 for January 1, 2009.
Any help would be greatly appreciated.
Thanks
Phillip Gatte
Post #843738
GSquared
GSquared
Posted Thursday, January 07, 2010 11:09 AM
SSCoach
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
You could convert using style 10, then wrap that in a replace that gets rid of the punctuation.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #843741
jcdyntek
jcdyntek
Posted Thursday, January 07, 2010 11:22 AM
SSC Rookie
Group: General Forum Members
Last Login: Thursday, May 27, 2010 11:01 AM
Points: 47,
Visits: 130
SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 1), '/', '') AS [MMDDYY]]
you would need to replace GETDATE() function with your date field. This will display as
010710.
Are the leading zeros a problem?
Post #843752
Ray K
Ray K
Posted Thursday, January 07, 2010 11:24 AM
SSCrazy
Group: General Forum Members
Last Login: Tuesday, March 19, 2013 6:25 PM
Points: 2,062,
Visits: 3,221
pgatte (1/7/2010)
I am new to SQL.
Can you tell me how I would convert a DateTime field to MMDDYY without any / or .
Example I would need the field to convert to 10409 for January 1, 2009.
Just checking: how do you get 10409 from Jan. 1 2009? (I'm assuming this is a typo.)
Also, don't underestimate fixed characters for dates. 10409 can be interpreted as either Jan. 4, 2009 (1/04/09) or Oct. 4, 2009 (10/4/09). I'd suggest including a leading zero so it reads 010409 (and is consistent with the MMDDYY format). That way, there's no confusion.
Post #843753
Lynn Pettis
Lynn Pettis
Posted Thursday, January 07, 2010 11:28 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 3:18 AM
Points: 21,588,
Visits: 27,375
Ray K (1/7/2010)
pgatte (1/7/2010)
I am new to SQL.
Can you tell me how I would convert a DateTime field to MMDDYY without any / or .
Example I would need the field to convert to 10409 for January 1, 2009.
Just checking: how do you get 10409 from Jan. 1 2009? (I'm assuming this is a typo.)
Also, don't underestimate fixed characters for dates. 10409 can be interpreted as either Jan. 4, 2009 (1/04/09) or Oct. 4, 2009 (10/4/09). I'd suggest including a leading zero so it reads 010409 (and is consistent with the MMDDYY format). That way, there's no confusion.
Even then, if you don't know it is stored as MMDDYY, 010409 could still be confused as Jan 4, 2009 or Apr 1, 2009. Just something to be aware of depending on who will be seeing the data. You may want to be sure this is documented appropriately.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #843757
LutzM
LutzM
Posted Thursday, January 07, 2010 11:59 AM
SSCertifiable
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 3:17 PM
Points: 6,731,
Visits: 12,131
To even confuse a little more, 010409 might be as well interpreted as April 9th 2001...
I probably would even include the format in the string and truncate it where needed (e.g. 010409MDY). I don't expect it to be used in any calculation...
Lutz
A pessimist is an optimist with experience.
How to get fast answers to your question
How to post performance related questions
Links for
Tally Table
,
Cross Tabs
and
Dynamic Cross Tabs
,
Delimited Split Function
Post #843786
pgatte
pgatte
Posted Thursday, January 07, 2010 11:59 AM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, July 05, 2011 2:47 PM
Points: 3,
Visits: 101
Thank you! That worked!
Phillip
Post #843787
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.