Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 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 May 14th, 2007, 04:58 PM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date format

Can someone give me a simple way to format a data entry from dd/mm/yyyy to dd/mm/yy? Thanks!

Tad
 
Old May 14th, 2007, 11:43 PM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this date format in C# or SQLSERVER

 
Old May 15th, 2007, 12:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Here you go.
Code:
select convert( varchar(10), getdate(), 3 )
_________________________
- Vijay G
Strive for Perfection
 
Old May 15th, 2007, 09:48 AM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help. This is not a system date but a data entry in the mm/dd/yyyy format that I need to convert to mm/dd/yy. I have tried using the convert string function but unsuccessfully.


Tad
 
Old May 15th, 2007, 09:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I understand, since it was not mentioned in the original post if that was a variable or a column name or something else that you try to convert, I just gave you the example with GETDATE(). Moreover, no clue about if you are trying to do that from sql server or from the front end application, though it was posted under sql server forum, thought I will post the example in t-sql.

Cheers.

_________________________
- Vijay G
Strive for Perfection
 
Old May 15th, 2007, 10:03 AM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is in SQL SERVER and I'm trying to script it during a runtime commmand. Our application fails when the data is in the mm/dd/yyyy format.

Tad
 
Old May 15th, 2007, 11:05 AM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I finally figured it out. If anyone needs it:

UPDATE [Table_Name]
          SET [Column_Name1] = CONVERT(CHAR(4),[Column_Name1])+ RIGHT([Column_Name1],2)

Tad
 
Old May 15th, 2007, 11:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

What datatype is your column_name1?

_________________________
- Vijay G
Strive for Perfection
 
Old May 15th, 2007, 11:43 AM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I see why you ask, varchar. I could have used LEFT(). But now I have another issue. I have been working on a date that is 5/6/2007. What if I get 12/12/2007? Is there a way to remove the last four characters of a string? So, I could go...
(function for removing right 4 characters of string) + RIGHT()

Tad
 
Old May 15th, 2007, 12:37 PM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So, this ended up being a string manipulation using a CASE statement. If anyone knows how to do this differently using a date format, I'd like to know. Thanks for the help Vijay!

Tad





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
Help with date format gregalb SQL Server 2000 1 February 13th, 2007 10:15 AM
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





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