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.