Click here to Skip to main content
15,886,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

am working on Asp.Net, C#, SqlServer 2005.

I have a Table in SqlServer 2005 DataBase.

In this Table i have a column name DateValidFrom with Data Type as (Datetime) and when i run this table with Query the column displays as
2013-01-15 00:00:00.000

and When i load this database table to asp.net Gridview it is displaying same as 2013-01-15 00:00:00.000 But I dont need time Just I need like this format 2013/01/15.

Please help. thanks.
Posted

Try the below query when selecting the data.
SQL
SELECT CONVERT(char(10), GetDate(), 111) --2013/01/15

Replace GetDate() with the Column Name.

Thanks...
 
Share this answer
 
Take the Date into a DateTime property or variable and use ToShortDateString() method of datetime in your C# code OR at you can convert the date to shortdate using :-
SQL
Select Convert(VarChar, GetDate(), 101)


Thanks,
 
Share this answer
 
v2
Try formating the date as shown below
SQL
SELECT REPLACE(convert(varchar, getdate(), 102),'.','/') --2013/01/15


Refer
SQL Server Date Formats[^]
How to format datetime & date in Sql Server[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900