• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 659
  • Last Modified:

SQL Server 2008 Date

in  SQL server 2008 date values is comming yyyy-dd-mm (eg:2010-11-16). i need to convert it to DD/MM/YY . i need to changed the Date filed Called Orderdate
0
lankapala
Asked:
lankapala
  • 6
  • 5
  • 2
  • +2
1 Solution
 
cyberkiwiCommented:
Is it coming in as a varchar?
convert(char(8), Orderdate, 3)
0
 
cyberkiwiCommented:
If orderdate is a date field, then it is internally stored without formatting - that is a function of the display.
0
 
lankapalaAuthor Commented:
Orderdate in my database is datetime, i need to permantly convert to my Orderdate date type DD/MM/YY, if i used
select Select convert(char(8), Orderdate, 3) from Orders; it will show only that time, i need to change Permently.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
lankapalaAuthor Commented:
is possible to use below code
ALTER TABLE Orders
ALTER COLUMN  OrderDate  convert(char(8), OrderDate, 3)

0
 
cyberkiwiCommented:
see http:#a34151053
If the field is datetime, there is NO inherent formatting.  It is stored internally as some numeric value, not a string in yyyy-mm-dd nor dd/mm/yy or any text.

You need to specifically format it on display, be it in SSMS or other.
The only other option is to change the field to Char(8) for dd/mm/yy but doesn't sound like what you want.
0
 
cyberkiwiCommented:
If you want to permanently change the column type to char containing dd/mm/yy then

alter table orders add orderdate2 char(8);
update orders set orderdate2 = convert(char(8), orderdate, 3);
alter table orders alter column orderdate char(8);
update orders set orderdate = orderdate2;
alter table orders drop column orderdate2;
0
 
Anthony PerkinsCommented:
>>in  SQL server 2008 date values is comming yyyy-dd-mm<<
As cyberkiwi has pointed out that is simply not correct.  You are confusing SQL Server 2008 with SSMS.  SSMS is the application used to view data in MS SQL Server.  The date data type has no interal formatting whatsoever.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>it will show only that time, i need to change Permently.

can you please explain why you need that?

I presume that a computed column would be the "best" solution, as having a date stored in varchar field with that format you request is highly ... unprofessional, as it WILL result in unefficient queries...
0
 
lankapalaAuthor Commented:
Not working
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
WHAT is not working?
WHAT is the error message?
0
 
Anthony PerkinsCommented:
lankapala,

>>Not working<<
If you honestly want to get a solution to your question consider providing more feedback.

Supposing your took your car to be repaired and told your mechanic that it was "Not working".  What do you think would be his/her response?
0
 
lankapalaAuthor Commented:
Appologies for puting not working,
I need to permentaly change date type dd/mm/yyyy ,
below coding is working perfectly,but its not DATE type
update orders set orderdate2 = convert(char(8), orderdate, 3);
alter table orders alter column orderdate char(8);
update orders set orderdate = orderdate2;
alter table orders drop column orderdate2;

I need to change it UK format.

i try using below coding its not working
USE master
GO
ALTER LOGIN Ryan WITH DEFAULT_LANGUAGE = British
GO
SET DATEFORMAT dmy;
EXEC sp_defaultlanguage 'Ryan', 'british'
SELECT * FROM sys.syslanguages


SET DATEFIRST 1

i try below coding
ALTER TABLE Orders
ALTER COLUMN  OrderDate  convert(char(8), OrderDate, 3)

error showing
Incorrect syntax near the keyword 'convert'.


Can any one help me to solve this issue
0
 
cyberkiwiCommented:
What is the datatype of the column OrderDate?
If it is CHAR containing yyyy-mm-dd, and you want it changed to DATE then

alter table orders add orderdate2 datetime; -- or DATE for sql 2008
update orders set orderdate2 = case when isdate(orderdate) then orderdate end;
alter table orders alter column orderdate datetime;
update orders set orderdate = orderdate2;
alter table orders drop column orderdate2;

If it is ALREADY DATE(TIME), then you're going up a steep hill.  There is no inherent format to DATE fields.
SSMS will ALWAYS show a datetime (unless you convert it to some specific char format) as "yyyy-mm-dd hh:mm:ss.zzz" because you CANNOT set a "display format" against a DATE(TIME) field.
If you want you can add a computed column that will always display dd/mm/yy though.

ALTER TABLE orders ADD OrderDateDisplay convert(varchar,orderdate,3)

Finally, you also have a very confused question
yyyy-dd-mm (eg:2010-11-16)
Is it DD-MM or MM-DD ???

If it is REALLY coming in as varchar yyyy-dd-mm, AND the field orderdate is currently VARCHAR, then add the dateformat before using the first block of code in this comment

set dateformat ydm
-- remember to set it back to dmy after the operation
-- set dateformat dmy
0
 
cyberkiwiCommented:
I really have to repeat this

There is no inherent format to DATE(TIME) fields.
SSMS will ALWAYS show a datetime (unless you convert it to some specific char format) as "yyyy-mm-dd hh:mm:ss.zzz" because you CANNOT set a "display format" against a DATE(TIME) field.
0
 
lankapalaAuthor Commented:
ok
0
 
QlemoC++ DeveloperCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 6
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now