Manish Tiwari Manish Tiwari - 8 months ago 79
SQL Question

How to get only date from date time using Asp. Net c#?

In sql database, value is in this format

and it's datatype is

But when i am getting it gives me like that :
7/16/16 12:00:00 AM

I want to get only the date
but with this format

How to get it?


When you fetch the data from the sql you should manipulate the data and change this value. i don't know if your using linq or using EF.

if you use linq

var query = from p in db.table
            select new view{
               CreatedOn = p.CreatedOn.ToString("dd/MM/yyyy")

but if you use EF and code first you can set the GET method on its property like this :

private datetime _createdOn;

public datetime CreatedOn {

    get {
         return _createdOn.ToString("dd/MM/yyyy");
        _createdOn = value;