Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6345047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:44:54+00:00 2026-05-24T20:44:54+00:00

In MVC razor, I am putting current date in the database like this.. model.Returndate

  • 0

In MVC razor, I am putting current date in the database like this..

model.Returndate = DateTime.Now.Date.ToShortDateString();

Since the database field is a datetime datatype and I am converting the current date to string format, this is not working.. how can I do this? I am doing the string format because I want the date in mm/dd/yyyy format and not in mm/dd/yyyy hh:mm:ss time format..

EDIT:

In the controller I have

var model = new ViewModel();
model.ReturnDate = DateTime.Now;            
return PartialView("PartialView", model);  

In the partialview, I have

@Html.EditorFor(model => model.Returndate)

This is where its displaying the date as Date and Time together… I want just the date to be displayed. Not the time. I hope this edit explains better.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:44:55+00:00Added an answer on May 24, 2026 at 8:44 pm

    If the column type is DateTime in SQL then it will store a time where you pass one or not.

    It’d be better to save the date properly:

    model.ReturnDate = DateTime.Now;
    

    and then format it when you need to display it:

    @Html.Label(Model.ReturnDate.ToShortDateString())
    

    Or if you’re using EditorFor:

    @Html.EditorFor(model => model.ReturnDate.ToShortDateString())
    

    or

    @Html.EditorFor(model => model.ReturnDate.ToString("MM/dd/yyyy"))
    

    To add a property to your model add this code:

    public string ReturnDateForDisplay
    {
        get
        {
           return this.ReturnDate.ToString("d");
        }
    }
    

    Then in your PartialView:

    @Html.EditorFor(model => model.ReturnDateForDisplay)
    

    EDIT:

    I just want to clarify for this answer that by my saying ‘If you’re using EditorFor’, that means you need to have an EditorFor template for the type of value you’re trying to represent.

    Editor templates are a cool way of managing repetitive controls in MVC:

    http://coding-in.net/asp-net-mvc-3-how-to-use-editortemplates/

    You can use them for naive types like String as I’ve done above; but they’re especially great for letting you template a set of input fields for a more complicated data type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Telerik Date Picker for ASP.Net MVC Razor Form. In this form
I want to set up a text area on an MVC razor page like
I'm using devExpress 11.1 with MVC 3/razor and i'm experiencing problems with putting html
I have javascript function mixed with ASP MVC Razor that get data from database
I am using ASP.NET MVC Razor And Data Annotation validators My model: public class
I'm having an odd problem with asp.net MVC razor view. I want my model
I have an EF model in a .NET 4.0 MVC Razor application. I'm pulling
I am using the following date picker in a mobile asp.net mvc razor website
In my Razor MVC application, I added the feature where a model property allows
I am working on my 1st mvc razor project. I set the project and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.