Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<asp:BoundField DataField="DateofBirth" DataFormatString="{0:dd/MM/yyyy}" HeaderText="Date of Birth" />
                            <asp:boundfield datafield="DateofBirth" dataformatstring="{0:MMMM d, yyyy}" htmlencode="false" />




i am storing date from my text box to database 12/12/1987

when i papulate my grid view it display the date like this 12/12/1987 12:00:00 AM

i use above mentioned dataformatting string.

but i did not get my result

i need 12/12/1987 only, no need of time
Posted

Try this:
ASP.NET
<asp:boundfield datafield="DateofBirth" xmlns:asp="#unknown">
                    HeaderText="Date of Birth" 
                    SortExpression="ModifiedDate" 
                    DataFormatString="{0:d}" /></asp:boundfield>


Read BoundField.DataFormatString Property[^]


--Amit
 
Share this answer
 
Update your query and add this line to your date column:
SQL
SELECT CONVERT(nvarchar, GETDATE(), 101)


[Updated]
Use EntityFunctions.TruncateTime Method [^]

Also check this similar discussion: Select date from datetime[^]
 
Share this answer
 
v3
Comments
prince_rumeel 14-Mar-13 5:55am    
about which query you are talking dear

i am not using any query
Prasad_Kulkarni 14-Mar-13 5:59am    
Oops my bad! Please see updated answer.
prince_rumeel 14-Mar-13 6:14am    
thx man
Prasad_Kulkarni 14-Mar-13 6:16am    
You're welcome!
Glad it helps.
 
Share this answer
 
Comments
prince_rumeel 14-Mar-13 5:51am    
bro at the time of data storing in the database it is storing 12/12/1987
but when using LinqToSQL getAll_Date method then it bind 12/12/1987 12:00:00AM in grid

public IList GetAllPatients()
{
CastroDataContext objDAL = new CastroDataContext();

var varPatients = (from cat in objDAL.Patients
where cat.IsDeleted.Equals(false)
select new
{
PatientID = this.ToInteger(cat.PatientID),
FirstName = this.ToString(cat.FirstName),
LastName = this.ToString(cat.LastName),
Gender = this.ToString((cat.Gender == "0") ? "Male" : "Female"),
DateOfBirth = this.ToString(cat.DateofBirth),
AccompaniedBy = this.ToString(cat.AccompaniedBY),
RefferedBy = this.ToString(cat.ReferredBy),
RefferalPhoneNumber = this.ToString(cat.ReferralPhoneNumber),
RefferalEmail = this.ToString(cat.ReferalEmail),
Race = this.ToString(cat.Race),
MaritalStatus = this.ToString(cat.MaritalStatus),
EmploymentStatus = this.ToString(cat.EmploymentStatus),
Address1 = this.ToString(cat.Address1),
Address2 = this.ToString(cat.Address2),
City = this.ToString(cat.City),
State = this.ToString(cat.State),
ZipCode = this.ToInteger(cat.ZipCode),
PatientPrimaryPhone = this.ToInteger(cat.PatientPrimaryPhone),
PatientSecoundaryPhone = this.ToInteger(cat.PatientSecondaryPhone),
PatientCellNumber = this.ToInteger(cat.PatientCellNumber),
PatientOtherNumber = this.ToInteger(cat.PatientOtherNumber),
PatientPrimaryEmail = this.ToString(cat.PatientPrimaryEmail),
PatientSecoundaryEmail = this.ToString(cat.PatientSecondaryEmail),
InsuranceCompanyName = this.ToString(cat.InsuranceCompanyName),
InsuranceProviderName = this.ToString(cat.InsuranceProviderName),
InsuranceProviderType = this.ToString(cat.InsuranceProviderType),
InsuranceGroupNumber = this.ToString(cat.InsuranceGroupNumber),
InsuranceID = this.ToInteger(cat.InsuranceID),
MRN = this.ToInteger(cat.MRN),
});


return varPatients.ToList();}

this is my dal function which is getting value from database
make your column data type is 'date', then it will store only date..
 
Share this answer
 
Comments
prince_rumeel 14-Mar-13 5:42am    
in database column is already date
and there is date in this formate
1987-12-12

but when i get it then it look like 12/12/1987 12:00:00AM
Hi

Try This Query while retrieving data from database



select CONVERT(varchar(20), docdate, 103) from sales



Thanks
Shafi
 
Share this answer
 
Comments
prince_rumeel 14-Mar-13 5:37am    
I am using LinqToSQL

so no store procedure i am using
 
Share this answer
 
Comments
prince_rumeel 14-Mar-13 5:32am    
Nothing happen

i already use that
but no gain

it is still displaying 12/12/1987 12:00:00 AM

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