Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DatePart

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2012-02-22 : 11:07:40
Hi All,

I have one column DOJ and now i wanted to convert so that i can display the Tenure

YY:MM:DD

Please suggest

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-02-22 : 12:30:48
Display = front end. who cares what it looks like in the database.

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-22 : 12:31:55
What's the Datatype of DOJ in the table?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2012-02-24 : 09:38:08
The data type is DateTime
Go to Top of Page

Jayam.cnu
Starting Member

45 Posts

Posted - 2012-02-24 : 09:46:54
Then change it to Varchar and while inserting you can insert in that format only ..
like convert(varchar,month(doj))+':'+convert(varchar,day(doj))+':'+convert(varchar,year(doj)).....

i think there is not special datatype to change in that format
... may we can create user defined datatypes to get that format...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-24 : 09:58:31
quote:
Originally posted by Jayam.cnu

Then change it to Varchar and while inserting you can insert in that format only ..
like convert(varchar,month(doj))+':'+convert(varchar,day(doj))+':'+convert(varchar,year(doj)).....

i think there is not special datatype to change in that format
... may we can create user defined datatypes to get that format...



Not at all a recommended approach
as this makes date manipulations difficult
try to store them as date type itself
and in front end apply formatting functions to get it in way you need. All front end applications as well as reporting tools have such functions entirely for these purpose

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -