Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove time from datetime field 1

Status
Not open for further replies.

cathiec

Programmer
Joined
Oct 21, 2003
Messages
139
Location
IE
i have a datetime field in sql server table - PAYMENTDATE.
i select this using a stored procedure and populate a dropdownlist in ASP.NET with the values that are returned.

this is the code that i use:

if(ds.Tables[0].Rows.Count!=0)
{
DropDownList1.DataSource = ds;
DropDownList1.DataMember = "CLAIMSPERD_EMF";
DropDownList1.DataTextField = "ACTIVE_PERIOD";
DropDownList1.DataBind();
}

this all works fine but the date appears in the dropdownlist with as a date and time field (the time is 00:00:00) so it might look something like this:
2001-09-30 00:00:00.000

i don't store the time initially in the field and i don't need it either.

is there a way to remove this 00:00:00 from the date in the dropdownlist.

i hae tried Substring(0,8).ToString() on both the left and right sides of the line:

DropDownList1.DataTextField = "ACTIVE_PERIOD";

bu this gives me errors.

in the table in sqlserver the date is stored as 2001-09-30 when i return all rows but if i use query analyser and run a query the date comes back ike 2001-09-30 00:00:00.000

i have tried
any help would be much appreciated!

thanks!
 
you have the DataTextFormatString property that does what you need.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
thanks!
i used the DataTextFormatString like so:
DropDownList1.DataTextFormatString ="{0:d}";
this gives me the date in the format dd/mm/yyyy
 
you could also create a function on the database I have one for time and date
Code:
/*get an string value of a time in hh:mm:ss format*/
ALTER       FUNCTION fn_TimeOnly(@Time datetime)
 RETURNS varchar(8)
AS
 BEGIN
    RETURN CONVERT(varchar(8), @Time, 108)
 END

/*get an string value of a date in mm/dd/yyyy format*/
ALTER  FUNCTION fn_DateOnly(@Date datetime)
 RETURNS varchar(12)
AS
 BEGIN
    RETURN CONVERT(varchar(12), @Date, 101)
 END

Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top