Remount date with javascript

1

In my database I have a DateTime field. In my form I have three combos for: Day, Month and Year. I have a JavaScript function which serializes the information, sending them to my controller to record. It turns out that the date is coming null. I tried to do this, but it does not work.

DataNascimento:
    ($("input[name='txtAno']").val() + "-" +
    $("input[name='txtMes']").val() + "-" +
    $("input[name='txtDia']").val()),

How do I date the date in javascript?

    
asked by anonymous 19.03.2014 / 21:04

3 answers

2

Well, your question is "How do I date the date in javascript?" And I answer you, it's simple, to build a Date you have the Javascript Date Object:

var a = $("input[name='txtAno']").val(); //ano
var m = $("input[name='txtMes']").val(); //mes
var d = $("input[name='txtDia']").val(); //dia
var data = new Date(a,(m-1),d); //o m-1 é porque o mês do javascript é zero-indexed.

Soon you will have a Date reassembled in javascript, and you can use it for your function.

    
19.03.2014 / 21:09
0

I see that you already have the data inputs dismembered, you could create an action, which instead of receiving a date, also receive the parts dismembered:

public ActionResult MinhaAction(int txtAno, int txtMes, int txtDia)
{
    var data = new DateTime(txtAno, txtMes, txtDia);
}
    
19.03.2014 / 21:07
0

I found a library of js on the internet the other day that helped me a lot with issues related to the date in Javascript. Follow the download link from the library:

DATE JS

    
19.03.2014 / 21:27