Reputation: 3830
I'm working in ASP using MVC 4, and i try to create a date with a specif day. For example, the user insert day 19
, and i in controller will create a date 19/02/2014
for example...
How can i do this?
Upvotes: 0
Views: 4450
Reputation: 4727
You can create a new DateTime
as follow:
var myDate = new DateTime(2014, 2, 19);
Also see the MSDN on http://msdn.microsoft.com/en-us/library/xcfzdy4x(v=vs.110).aspx.
And if you would like to create a controller action which results the date by day, try the following:
public ActionResult GetDate(int day)
{
var now = DateTime.Now;
var myDate = new DateTime(now.Year, now.Month, day);
return Content(myDate.ToShortDateString());
}
Upvotes: 3
Reputation: 955
DateTime has a constructor which will take a year,month,day
http://msdn.microsoft.com/en-us/library/xcfzdy4x(v=vs.110).aspx
DateTime someDate = new DateTime(2014, 2, 19);
You can replace 19 with your variable from your ViewModel.
Upvotes: 1
Reputation: 19830
The following code should work for you:
var input = 19;
var d= new Date(2014,2,input);
Upvotes: 1