Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 SQL .ASP datetime

Author  Topic 

teedah1
Starting Member

10 Posts

Posted - 2007-05-03 : 15:40:29
Hi all, I am trying to truncate the time portion in datetime in .ASP.

Column is showing a sql datetime field of mm/dd/yyyy 12:00:00 AM. how do I remove this time piece and just leave the date? Do I do it in SQL or ASP? Thanks for your advice.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-03 : 15:42:36
dates in the database are always stored with date and time.

so are you trying ti "fix" your data in a table or you're having presentation issues where you want to format the date string?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

teedah1
Starting Member

10 Posts

Posted - 2007-05-03 : 15:47:01
Hi spirit, yes, i am trying to truncate that default 12:00:00 AM when it is displayed on the asp Gridview column.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-03 : 15:50:16
The gridView's columns all have a CellStyle property, and there you can set the Format property to be whatever you want for the column's data, for example MM/dd/yyyy.

Edit: I just noticed that you said ASP, so I assume that this is ASP.NET, not windows forms. In that case, the BoundField object has a DataFormatString property that you can set, in much the same way.

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-03 : 15:51:05
use
yourDateTimeVariable.ToShortDateString()
or
yourDateTimeVariable.ToString("yyyy-MM-dd");

or use any other format you wish in the ToString() ,ethod


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-03 : 15:51:48




_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -