SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Date Format


Date Format

Author
Message
Minnu
Minnu
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3229 Visits: 950
Hi Team,

Am using below code to display name and "Date of birth"
but Field DOB is not coming in Date format.

select @FinalString=(SELECT RTRIM(+ISNULL('Name ','')+' : ' +ISNULL(+CAST(NAME AS VARCHAR(100))+' ','') +ISNULL(' DOB :'+CAST(DOB AS VARCHAR(100))+' ',''))
FROM ETCOL
i want date format in below format.

rtrim(convert(varchar, DOB,107)) + ')'

Can u please help me .....
anthony.green
anthony.green
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62382 Visits: 8587
Can you provide some sample data of the format that the DOB is and how it should be formatted



How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


Minnu
Minnu
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3229 Visits: 950
Date format in DOB Column is : '2012-09-30 00:00:00.000'

i want date format in : Sep 30, 2012
anthony.green
anthony.green
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62382 Visits: 8587
Well that converts perfectly.

Can you provide the DDL and sample data for table ETCOL along with your full query?



How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


Minnu
Minnu
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3229 Visits: 950
BEGIN
select @FinalString =(SELECT RTRIM(+ISNULL('Name','')+' : ' +ISNULL(+CAST(Name AS VARCHAR(100))+' ',''))
FROM ETCOL WHERE RIGHT_TEXT ='Name') +CHAR(10)
END

ELSE
BEGIN
select @FinalString=(SELECT RTRIM(+ISNULL('Name','')+' : ' +ISNULL(+CAST(Name AS VARCHAR(100))+' ','') +ISNULL(' DOB :'+CAST(DOB AS VARCHAR(100))+' ',''))
FROM ETCOL WHERE RIGHT_TEXT ='Name') +CHAR(10)
END

----------

If the DOB is not null, then i want the date format like : Sep 30, 2012
anthony.green
anthony.green
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62382 Visits: 8587
Please post the create table definition along with data for the table so what we can build up the string for you.



How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


Minnu
Minnu
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3229 Visits: 950
CREATE TABLE ETCOL (NAME VARCHAR (50), DOB DATETIME)
anthony.green
anthony.green
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62382 Visits: 8587
And now some data?



How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


Minnu
Minnu
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3229 Visits: 950
Hi Team,

Table and data is normat,

in my query am checking whether it is null or not null and
am not converting to normal date format.


can u please convert it to normal date if it is not null.

Please help me.....
DiverKas
DiverKas
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1067 Visits: 460
Minnu (12/5/2012)
Hi Team,

Am using below code to display name and "Date of birth"
but Field DOB is not coming in Date format.

select @FinalString=(SELECT RTRIM(+ISNULL('Name ','')+' : ' +ISNULL(+CAST(NAME AS VARCHAR(100))+' ','') +ISNULL(' DOB :'+CAST(DOB AS VARCHAR(100))+' ',''))
FROM ETCOL
i want date format in below format.

rtrim(convert(varchar, DOB,107)) + ')'

Can u please help me .....


If you want it formated like
 rtrim(convert(varchar, DOB,107)) 

then use it in the select statement?

 select @FinalString=(SELECT RTRIM(+ISNULL('Name ','')+'  : ' + 
ISNULL(+CAST(NAME AS VARCHAR(100))+' ','') +
ISNULL(' DOB :'+rtrim(convert(varchar(10), DOB,107)) +' ','')) FROM ETCOL



I prefer to be explicit with my CONVERT(VARCHAR(12), DOB,107), since you are going to get a 30 character varchar variable by default, instead of the 12 character that you need.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search