Reputation: 97
I have a date in this format: 05-Jun-2013, I just need year and it need to be converted to just 2013, for my validation purpose. How can I do this, please be concerned that, .getFullYear() is not working.
Upvotes: 0
Views: 3418
Reputation: 28773
Try with split like
my_date = '05-Jun-2013';
var my_arr = my_date.split('-');
alert('The year is ' + my_arr[2]);
Here my_arr is the array and my_arr[2] will represents the year
Upvotes: 0
Reputation: 1628
By default getFullYear should work. Might be a possibility that you are not having the appropriate object for usage.
You follow this approach
var dateString = "05-Jun-2013";
var dateStringArray = dateString.split("-");
var yearValue = dateStringArray[2];
Upvotes: 0
Reputation: 7302
Try this it's working for me:
var d = '05-Jun-2013';
var nd = new Date(d);
alert(nd.getFullYear());
Upvotes: 0
Reputation: 31072
Please see below.
var dateObj = new Date("05-Jun-2013");
dateObj.getUTCFullYear();
Upvotes: 0