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
 Transact-SQL (2005)
 Eliminating time from date

Author  Topic 

parrot
Posting Yak Master

132 Posts

Posted - 2008-06-29 : 21:44:56
How can I eliminate the time portion from a date field when displaying in a GridView on a web page? For example, 10/04/2004 displays as 10-04-2004 12:00:00 AM. I want to get rid of the 12:00:00 AM suffix. The dates display properly in a Windows environment but not in a Web page. The fields are defined as smalldatetime and even using the REPLACE command will not get rid of the time suffix.
Dave

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-06-29 : 21:55:48
you have to use this to whatever format you want:

http://msdn.microsoft.com/en-us/library/ms187928.aspx

Like: select convert(char(8),getdate(),5)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-06-29 : 21:57:51
don't convert or format it to string at the SQL side. Format to the required format in your front end web when displaying.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

parrot
Posting Yak Master

132 Posts

Posted - 2008-06-30 : 00:20:51
Thanks for everyone's help. I used the convert command as suggested , convert(char{8), 1) and got my intended result. Thank God for these forums. I really don't know how to use khtan's suggestion as I am using the OleDBDataAdapter FILL command to populate my GridView rather than using the OleDBReader command and therefore don't have access to each individual record.
Dave
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-30 : 00:37:06
quote:
Originally posted by parrot

Thanks for everyone's help. I used the convert command as suggested , convert(char{8), 1) and got my intended result. Thank God for these forums. I really don't know how to use khtan's suggestion as I am using the OleDBDataAdapter FILL command to populate my GridView rather than using the OleDBReader command and therefore don't have access to each individual record.
Dave


Use Format(yourdatecol,"dd/mm/yyyy") inside query you give for commandtext of OleDBDataAdapter
Go to Top of Page
   

- Advertisement -