asp.net - conversion to DateTime -
i have following tags select date first day,second month , third year
<select id="d" class="styledselect-day" tabindex="6"> <option value="">dd</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select id="m" class="styledselect-month" tabindex="7" > <option value="">mm</option> <option value="1">jan</option> <option value="2">feb</option> <option value="3">mar</option> <option value="4">apr</option> <option value="5">may</option> <option value="6">jun</option> <option value="7">jul</option> <option value="8">aug</option> <option value="9">sep</option> <option value="10">oct</option> <option value="11">nov</option> <option value="12">dec</option> </select> <select id="y" class="styledselect-year" tabindex="8"> <option value="yyyy">yyyy</option> <option value="2005">2005</option> <option value="2006">2006</option> <option value="2007">2007</option><option value="2008">2008</option><option value="2009">2009</option><option value="2010">2010</option><option value="2011">2011</option><option value="2012">2012</option> </select>
and following js code, using sending information controller. storing these information in session
$.ajax({ type: "post", url: "@url.action("acceptpersonalinfo","register")", data: { dateday: $("#d").val(), datemonth: $("#m").val(), dateyear: $("#y").val() }, success: function () { $("#contentspan").load("/register/contactinfo"); } });
following session code
public void acceptpersonalinfo(string dateday, string datemonth, string dateyear) // { session["dateday"] = dateday; session["datemonth"] = datemonth; session["dateyear"] = dateyear; }
then have store date in datetime object save databse.
p.dob = convert.todatetime(convert.toint32(session["datemonth"]) + convert.toint32(session["dateday"]) + convert.toint32(session["dateyear"]));
but not converting datetime. "p.dob" of datetime type. pls why conversion failed.
actually adding integers thats why not getting. try below code
string date = session["datemonth"].tostring() + "-" + session["dateday"] + "-" + session["dateyear"]; p.dob=convert.todatetime(date);
Comments
Post a Comment