Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
var date = (from rec in dcBusinessAccountingContext.WorkOrdersReportSP_Results select rec.Date);

Here "var date" will have all date's from WorkOrdersReportSP_Results with time stamp, next i want to convert that Date's to only Date without "Time Stamp" in C#
can anybody plz help me



thanks
Prashanth
Posted
Updated 18-Jul-13 7:35am
v2

You can do:
C#
date = date.Date;

but if you display it, it will still give you a DateTime with the timestamp reset 12:00 AM.

If you want to just display the date part of a DateTime in a grid for example, you can use the use ToString() formatting.

C#
date.ToString("d")
date.ToString("D")


Which will return:
7/18/2013
Thursday, July 18, 2013


Note: Doing ToShortDateString() and ToLongDateString() will give you the same thing respectively
 
Share this answer
 
Comments
Member 10070519 19-Jul-13 2:31am    
date.ToString("d") this is giving "Cannot implicitly convert error"
Silvabolt 19-Jul-13 9:26am    
You have to change your format type to a string and not a datetime.

e.g string dateString = date.ToString("d");
Hello,

Your value is like this

C#
var date = (from rec in dcBusinessAccountingContext.WorkOrdersReportSP_Results select rec.Date);
date = date.Date;
 
Share this answer
 
v2
Comments
Member 10070519 19-Jul-13 2:32am    
date = date.Date giving" System.Collections.Generic.IEnumerable<system.datetime?> does not contain definition for 'Date'"
Sorry,

The answer was:

var date = (from rec in dcBusinessAccountingContext.WorkOrdersReportSP_Results select rec.Date).FirstOrDefault();
date = date.GetValueOrDefault().Date;

I forgot to add FirstOrDefault().

But of course you must do the logic if date is null.
 
Share this answer
 
Comments
Naz_Firdouse 19-Jul-13 7:36am    
instead of posting it as another solution, please update your previous answer

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