hi everyone,
I need alter query whcih set my datetime field formate to dd/mm/yyyy
i tried
ALTER TABLE abc ALTER COlUMN mydate Format 'dd/mm/yyyy'
I know query syntax is wrong, can anyone provide me solution for this.
Thanks and Regards,
yash
Loading
Tina ThomasPosted Jul 30, 2010, 5:53 AM
I think you should not try to alter the table. You should leave the column with the datetime field unless its absolutely required.
so lets say you have a table
Person with 2 columns
PersonID(int)
DateCreated(datetime)
and you need to write a query that would return datecreated in the format dd/mm/yyyy without the time field, you can use change your query to
SELECT CONVERT(VARCHAR(10), DateCreated, 103) AS DateCreated FROM Person
You can change to a variety of date formats.
See link for further information.
http://msdn.microsoft.com/en-us/library/ms180878.aspx#UsingCastandConvertwithtimedatedatetime2anddatetimeoffset
--Tina