I have a restaurant based web project that I am currently working on and am having problems with Datetime.
I have WebMethodone that adds table reservations to a SQL Server database.
[WebMethod]
public void AddTable(string first, string last, string email, long telephone, int people, string special, DateTime bookingDate)
{
using (BookingLinqDataContext bl = new BookingLinqDataContext())
{
bl.AddTable(first, last, email, telephone, people, bookingDate, special);
}
}
This is the parsed data from an Ajax call:
$("#AddTableBut").click(function () {
var firstName = $("#FirstName").val();
var lastName = $("#LastName").val();
var email = $("#Email").val();
var telephone = $("#Telephone").val();
var numberPeople = $("#NumberPeople").val();
var date = $("#DateComing").val();
var special = $("#SpecialReq").val();
var Book = {
'first': firstName,
'last': lastName,
'email': email,
'telephone': telephone,
'people': numberPeople,
'special': special,
'bookingDate': date
}
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/PeldonRoseService.asmx/AddTable",
dataType: "json",
data: JSON.stringify(Book),
success: function () {
$("[id$=booking]").hide('blind', { direction: 'up' }, 2000);
$("#BookNowBut").delay(2100);
$("#BookNowBut").show('slide', { direction: 'right' }, 500);
}
});
});
When I check this, I add the date to the corresponding text box in the UK date format dd-MM-yyyy. However, I get this error from the Chrome Developer Toolbar:
Message: 04/30/2014 is not a valid value for DateTime.
However, if I use the American date format MM-dd-yyyy, everything works fine.
Could the problem be my browser culture information?