How to trim off the time part of a DateTime field

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I have a tabls of SQL 2000, about the data of student.
The data is migrate from another databse,
There is a field called birthday, it stores the data with the formate like:
1994/11/03 AM 02:09:00

When I bind the field to datagrid, how can I suppress the time part , or
how can I trim the time part form database?
 
you can use the CONVERT function in sql

try this:

CONVERT(varchar(20), Getdate(), 103)
 
If it is only for display purpose you can use this
Datime objDt = new datetime.now
objDt.ToString("MMM dd yyyy");

For any other purpose, you don't really need to do conversion.
[See DateTime.ToString in MSDN]

Ural
 
Thank,
But I don't just for desplay purpose.
I want to really trim off the time part of that field in database.

Could somebody tell me how to do?


ural said:
If it is only for display purpose you can use this
Datime objDt = new datetime.now
objDt.ToString("MMM dd yyyy");

For any other purpose, you don't really need to do conversion.
[See DateTime.ToString in MSDN]

Ural

mavisahdas said:
Hi Kent,

You can make use form Data Format string property of the grid columns to
format the date.

For more input Refer http://www.dotnetspider.com/technology/kbpages/384.aspx.

With regards,

Sadha Sivam S,
Microsoft Community Star,
Sr. Engineer,
Aspire Systems,
www.dotnetspider.com
 
Hi ad:

You can use CONVERT, as suggested ealier. The datetime datatype in SQL
will always store a time, however, even if the time is always 12:00
AM. SQL 2005 as far as I know dropped support for unique date and time
datatypes. The only other real choice is to just store a date as
varchar or nvarchar.

--
Scott
http://www.OdeToCode.com/blogs/scott/

Thank,
But I don't just for desplay purpose.
I want to really trim off the time part of that field in database.

Could somebody tell me how to do?


ural said:
If it is only for display purpose you can use this
Datime objDt = new datetime.now
objDt.ToString("MMM dd yyyy");

For any other purpose, you don't really need to do conversion.
[See DateTime.ToString in MSDN]

Ural

mavisahdas said:
Hi Kent,

You can make use form Data Format string property of the grid columns to
format the date.

For more input Refer http://www.dotnetspider.com/technology/kbpages/384.aspx.

With regards,

Sadha Sivam S,
Microsoft Community Star,
Sr. Engineer,
Aspire Systems,
www.dotnetspider.com



:

I have a tabls of SQL 2000, about the data of student.
The data is migrate from another databse,
There is a field called birthday, it stores the data with the formate like:
1994/11/03 AM 02:09:00

When I bind the field to datagrid, how can I suppress the time part , or
how can I trim the time part form database?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top