0

I am trying to set a Readonly textbox2 text property to current year. I am trying to set textbox2 text by using onchange() property on an above textbox1, this way after changing textbox2 text will be asigned as current year. Now the problem is, I have no idea how to work with date formats in jquery is to. Here I am doing it like this $("#<%=FromYear.ClientID%>").val(Date.now); but its not giving me year.

ABi
  • 143
  • 2
  • 18
  • 1
    if you want to set text property as year you need to write it .Text() instead of val() – ABi Aug 09 '16 at 21:37

4 Answers4

2

You need Date() function to use.

Example:

$("#id.ClientID").val(new Date().getfullYear());

OR

$("#id.ClientID").val(new Date().getYear());

If you want to know more about Date() function and its attributes? check this link

Community
  • 1
  • 1
ABi
  • 143
  • 2
  • 18
1
var s = new Date();

alert(s.getFullYear());
Husni Salax
  • 1,968
  • 1
  • 19
  • 29
1

Date.now will return the function code of the Date.now() function:

console.log(Date.now);
> function () { [native code] }

You want Date.getFullYear()

$("#<%=FromYear.ClientID%>").val(Date.getFullYear());
Nick Bull
  • 9,518
  • 6
  • 36
  • 58
0

$(document).ready(function(){

var today=new Date();

$('#DispalyDate').text("Full date=" + today.toDateString()); 
$('#FullYear').text("Full year=" + today.getFullYear()); 
$('#DayOfMonth').text("Day=" + today.getDate()); 
$('#GetMonth').text("Number of month=" + today.getMonth()); 

 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="DispalyDate"> </div>
<div id="FullYear"> </div>
<div id="DayOfMonth"> </div>
<div id="GetMonth"> </div>
Saffor
  • 60
  • 2
  • 11