If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > How to convert this date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-08-12, 16:11
biznez biznez is offline
Registered User
 
Join Date: Nov 2011
Posts: 24
Question How to convert this date

Hello everyone, hope all is well

in sql i needed to know how to convert the date YYYYMMDDHHMMSS TO CYYMMDD

thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 02-08-12, 17:39
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Code:
DECLARE @d		DATETIME = GetDate()

SELECT @d, CONVERT(CHAR(8), @d, 112)
,  CONVERT(VARCHAR, @d, 112) + REPLACE(CONVERT(VARCHAR, @d, 114), ':', '')
-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On