0

I have a date column called Today Date on one of the list forms. I am trying to auto-populate it and set it to current date when newform is opened. Its pulling current month and day value fine but not the accurate year value.

Below is the code I added on the new form.

<script src="https://code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    var today = new Date();   
    var todayDay = today.getDate();   
    var todayMon = today.getMonth() + 1;   
    var todayYear = today.getYear();   
    today=todayMon + "/" + todayDay + "/" + todayYear;  
    $("input[title='Today Date']").val(today);
})
</script>

Below is what I see on the form. enter image description here

Can anyone help, thanks.

1

As you have used today.getYear() it correctly returns 119. You have to add 1900 to the result.

You can also use today.getFullYear() which should return 2019.

  • Thanks peter, getFullYear worked. – mdevm Mar 21 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.