Reputation: 11
I have a table that contains 20,000 rows. I want to change my existing date format from 2016-04-04 to 4/4/16. I have googled it but I only found the solution for changing to the current time. This is my query.
UPDATE [master].[dbo].[TRY]
SET Target_Hire_Date = CONVERT(VARCHAR(20), GETDATE(), 103)
But this query only for the current time which is not working for my problem.
Upvotes: 0
Views: 523
Reputation: 1394
to have exactly the format d/m/yy, try this:
UPDATE [master].[dbo].[TRY]
SET Target_Hire_Date = convert(nvarchar,day(YOUR_EXISTING_DATE)) + '/'
+ convert(nvarchar,MONTH(YOUR_EXISTING_DATE)) + '/' +
convert(nvarchar,RIGHT(YEAR(YOUR_EXISTING_DATE),2))
just supposing the YOUR_EXISTING_DATE is DATETIME
is better to store dates in a DATE column, then choose the format with the query
Upvotes: 0
Reputation: 5893
UPDATE [master].[dbo].[TRY]
SET Target_Hire_Date =
CONVERT(VARCHAR(10),CAST(@a as DATE),103)
Upvotes: 0
Reputation: 5031
Use your date column instead.
UPDATE [master].[dbo].[TRY]
SET Target_Hire_Date = CONVERT(VARCHAR(20), [YOUR-DATE-COLUMN], 103)
Upvotes: 1