Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading a sql date

Status
Not open for further replies.

kmacko

Programmer
May 13, 2001
1
US
how do I display a date field that is generated by sql server and applied to each record that is enter. It is not a char. field.
 

Is the column defined as datetime or smalldatetime? If so, you can simply select the column in a query. If you run the query in SQL Query Anlayzer, the dates will display in the default date/time format. If you run a query in Access, Access will display the result in it's date/time format. If you run the query in another client software, you'll need to determine how the software displays dates.

SQL Server allows conversion of dates to different character formats using the Convert function. For example, if I want to guarantee that a date will be returned in yyyy/mm/dd format, I would use the following select statement.

Select convert (char(10), datecolumn, 111) As NewDate
From table1

datecolumn is the column name in table1. 111 is the date style which corresponds to yyyy/mm/dd format. NewDate is the name of the derived column. You can actually name the column the same name as on the table. Specify "As datecolumn" rather than "As NewDate."

See the topic, "CAST and CONVERT (T-SQL)" in SQL Books Online for more information about converting dates including the available styles. Terry

X-) "I don't have a solution, but I admire your problem."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top