Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2003, 06:09 AM
Authorized User
 
Join Date: Jun 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to format a Date field

How can I format a Date field in a SQL Server Table in any desired format such as (dd-mmm-yy) while querying with SQL Query Analyzer?
 
Old June 23rd, 2003, 06:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

The data is always stored the same way, as either a datetime or smalldatetime data type.

You can convert this internal representation to a character datatype by using either the CAST or CONVERT functions. For example:
Code:
SELECT CONVERT(varchar(10),yourdatetimecolumn,101) as Yourdateasvarchar
FROM ...
will return a 10 character string representation of the date as mm/dd/yyyy. See BOL for other values of the 'style' parameter of the CONVERT function.


Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old June 25th, 2003, 12:43 AM
Authorized User
 
Join Date: Jun 2003
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you can configure sql query analyzer to use a certain date / time format when converting datetime or smalldatetime data to string for displaying on the results pane like this: go to menu tools / options then on the connections tab check use regional settings....

the regional settings you can view / change from the control panel.

defiant.





Similar Threads
Thread Thread Starter Forum Replies Last Post
date format differs, need to force format somehow patricolsson ASP.NET 2.0 Basics 1 December 3rd, 2009 12:53 AM
Convert British format date to American format? fyr PHP How-To 0 December 19th, 2007 03:17 PM
How to give Date format while entering date Subuana Beginning VB 6 4 March 17th, 2006 07:25 AM
date format differs, need to force format somehow patricolsson HTML Code Clinic 2 January 12th, 2006 05:55 AM
Format Date to time field KennethMungwira VB.NET 3 November 17th, 2003 11:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.