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

  • Home
  • SEARCH
  • 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 8208701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:28:04+00:00 2026-06-07T09:28:04+00:00

It is very weird. I hava date format data that comes from Http GET,

  • 0

It is very weird. I hava date format data that comes from Http GET, and I wrap the date using model class. it is like this,

// Model

public class wrapModel
{
  public DateTime mydate{get; set;}
}

And,

// controller
[HttpGet]
public void myController(wrapModel data){
   Response.Write(searchModel.mydate.ToString());
}

and call the controller using browser, myhost/home/myController/mydate=05/05/2012

then it print “5/5/2012 12:00:00 AM” ,I expected 5/5/2012 only.

I do not need the time. so I tried to parse the date.

data.mydata = DateTime.parse(data.mydata.ToString("MM/dd/yyyy"));

but it still print “5/5/2012 12:00:00 AM”

How can I change the format to “5/5/2012”?

anybody know, please advice me~

Thank you!

I want to parse datetime format data that comes from Http GET.

but I does not changed and also

[EDIT]

Thank you for all the answers and your valuable time! but I am still in the problem. Please help me a little more 🙂

First of all, I need DateTime format data, not string type, becuase I will use the date in Linq to retrieve DB date.

I tried,

1)

[DisplayFormat(DataFormatString="{0:MM/dd/yyyy}", ApplyFormatInEditMode=true)]
public DateTime mydate { get; set; }

[HttpGet]
public ActionResult myController(wrapModel data){
   return Content(searchModel.mydate.ToString());
}

still it print “5/5/2012 12:00:00 AM”

2)

[HttpGet]
public ActionResult myController(wrapModel data){
   return Content(searchModel.mydate.ToString("MM/dd/yyyy"));
}

it changed foramt as well, but I need DateTime format so I convert to DateTime again.

[HttpGet]
public ActionResult myController(wrapModel data){
   searchModel.mydate = DateTime.Parse(searchModel.mydate.ToString("MM/dd/yyyy"));
   return Content(searchModel.mydate.ToString());
}

then it print “5/5/2012 12:00:00 AM” again.

3)

searchModel.etaDate.ToString("d")

same to above, convert to DateTime then it print “5/5/2012 12:00:00 AM”

And

I use Response.Write() for simple return value test, but is there any important reason I can not use the Response.Write() method? I want to learn 🙂

Thanks a lot!

[EDIT]

I need to DateTime type data for this,

Repository myRespository = new Respository();

var data = (from x in myRepository.myContext
            where x.thedate == mydate  // thedate is datetime type, so I need datetime type for compare
            select x.no).SingleOrDefault()

I tried,

string test = mydate.ToShortDateString();

(...
where x.thedate.ToString() == test
...)

but it does not work.

  • 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-06-07T09:28:06+00:00Added an answer on June 7, 2026 at 9:28 am

    How can I change the format to “5/5/2012”?

    You will first have to pass the parameter using the correct format which is always yyyy-MM-dd for GET requests:

    http://myhost/home/myController/mydate=2012-05-05
    

    I am stressing on the word always, because this is very important to understand. The reason for this is that the default model binder always uses InvariantCulture when parsing dates from GET requests and it uses the current culture when parsing dates from POST requests. There’s a nice article explaining this as well as the reasons behind this design decision.

    and then:

    Response.Write(searchModel.mydate.ToString("MM/dd/yyyy"));
    

    Well, actually, not Response.Write because you never do that in an ASP.NET MVC application, you’d rather return an ActionResult from a controller action:

    [HttpGet]
    public ActionResult MyAction(wrapModel data)
    {
        return Content(data.mydate.ToString("MM/dd/yyyy"));
    }
    

    or you will have your view model decorated with the DisplayFormat attribute:

    public class wrapModel
    {
        [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime mydate { get; set; }
    }
    

    or if you want to take into account the current culture short date format:

    public class wrapModel
    {
        [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
        public DateTime mydate { get; set; }
    }
    

    and then have your controller action pass this model to the view:

    public ActionResult MyAction(wrapModel data)
    {
        return View(data);
    }
    

    and of course inside the corresponding strongly typed view use the DisplayFor/EditorFor helpers to achieve the desired output in the desired format:

    @model wrapModel
    <span>
        @Html.DisplayFor(x => x.mydate)
    </span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a very weird problem that I've never had before when using
I have this very weird issue that I cant really get why it's not
This is a very weird problem. My app that runs just fine but somehow
I have come across a very weird error. I'm on Solaris 10, using Ruby
A very weird situation... Using the debugger in VS2010 I can look up a
I am getting a very weird error when using VBA in excel. I am
I've found it very weird that simple code like this is not valid: select
I have a very weird problem while trying to pass and SQL query using
I'm having a very weird situation that is driving me nuts. I have a
I've got a very weird issue. I've got this Procedure object that contains two

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.