Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
MVC4 Date difference

How can i show the days difference between 2 dates in the below form?
Could i use the viewbag or add a method to the page controller?


@Html.EditorFor(model => model.BookingFrom)
@Html.ValidationMessageFor(model => model.BookingFrom)


@Html.EditorFor(model => model.BookingTo)
@Html.ValidationMessageFor(model => model.BookingTo)


@Html.EditorFor(model => model.BookingDays)
@Html.ValidationMessageFor(model => model.BookingDays)


Would like the BookingDays to auto popluate depending on the days selected
If possible would like working days only
Posted
Comments
TryAndSucceed 17-Sep-13 11:18am    
Javascript would be your answer. Based on the selection, calculate value and assign to the model field.

1 solution

You no need to send a server call for taking the date difference. By using Javascript or jquery you can calculate the difference inthe client side itself
I highly recommend using the excellent datejs framework to easily do all your date time calculations
http://www.datejs.com/[^]
Hope this helps
 
Share this answer
 
Comments
Adam Jones 24-Sep-13 7:38am    
The dates are not stored on the server at this point.
Will need to use jQuery looking at it now as this will need to be done on the fly
The dates may change multiple times before submitted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900