Format Date | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Format Date

Please can someone help me? I am very new to SQL and do not know very much. I am trying to format a date which I get from a table via an odbc link. The date field is called birth_dt and at the moment it shows the year, month, date, time etc. Is there any way I can format it within the select birth_dt from table statement in order to just show day, month, year. Thank you for any help you can give me.
quote:Originally posted by amilnes Please can someone help me? I am very new to SQL and do not know very much. I am trying to format a date which I get from a table via an odbc link. The date field is called birth_dt and at the moment it shows the year, month, date, time etc. Is there any way I can format it within the select birth_dt from table statement in order to just show day, month, year. Thank you for any help you can give me.

YES, you can format the date as per your requirement in the select query. SELECT GETDATE() AS DateInformation
DateInformation
———————–
2006-12-13 09:07:25.833 (1 row(s) affected)
SELECT CONVERT(varchar(20),GETDATE(), 101) AS DateInformation DateInformation
——————–
12/13/2006 (1 row(s) affected) Replace your ‘birth_dt’ column for GETDATE() in the previous example.
Also, look for SQL Server Books Online and search for Datetime datatype (converting). To display results properly after format. Thanks,
DilliGrg
If you want to format the date in different style…
BOL: CAST and CONVERT functions…
Mohammed U.
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by amilnes</i><br /><br />Please can someone help me? I am very new to SQL and do not know very much. I am trying to format a date which I get from a table via an odbc link. The date field is called birth_dt and at the moment it shows the year, month, date, time etc. Is there any way I can format it within the <br /><br />select birth_dt from table statement <br /><br />in order to just show day, month, year.<br /><br />Thank you for any help you can give me.<br /><br /><br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br />Welcome on board! [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />Typically you would use the client’s formatting repertoire to achieve this. In this regard you might this helpful:<a target="_blank" href=http://www.sql-server-performance.com/fk_datetime.asp>http://www.sql-server-performance.com/fk_datetime.asp</a><br /><br />–<br />Frank Kalis<br />Moderator<br />Microsoft SQL Server MVP<br />Webmaster:<a target="_blank" href=http://www.insidesql.de>http://www.insidesql.de</a>
Thank you very much for all your help – I am sure I can move forward with it now.

1 If you use front end application, you should use format function there
2 Use convert function, only if you want to export formatted dates to TEXT file
3 Always use proper datatype DATETIME to store dates Madhivanan Failing to plan is Planning to fail
Thank you for the info. Now I need to find out how to format a date in php.
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by amilnes</i><br /><br />Thank you for the info. Now I need to find out how to format a date in php.<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br />Thats good anyway [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail
]]>