 |
| 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
|
|
|
|

May 14th, 2007, 04:58 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Date format
Can someone give me a simple way to format a data entry from dd/mm/yyyy to dd/mm/yy? Thanks!
Tad
|
|

May 14th, 2007, 11:43 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
this date format in C# or SQLSERVER
|
|

May 15th, 2007, 12:40 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Here you go.
Code:
select convert( varchar(10), getdate(), 3 )
_________________________
- Vijay G
Strive for Perfection
|
|

May 15th, 2007, 09:48 AM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 15th, 2007, 09:52 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|

May 15th, 2007, 10:03 AM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 15th, 2007, 11:05 AM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 15th, 2007, 11:16 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
What datatype is your column_name1?
_________________________
- Vijay G
Strive for Perfection
|
|

May 15th, 2007, 11:43 AM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 15th, 2007, 12:37 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |