Javascript and Dates
-
I have a string in the form of d+/d+/d+. For example, the string might be 1/1/2011. This string would represent the date January 1, 2011. This application uses a banker's year. That means 30 days for each and every month and 360 days to the year. Now, if I have this string in a variable d1 what is the best way to extract the year, month and day? Thanks Bob
-
I have a string in the form of d+/d+/d+. For example, the string might be 1/1/2011. This string would represent the date January 1, 2011. This application uses a banker's year. That means 30 days for each and every month and 360 days to the year. Now, if I have this string in a variable d1 what is the best way to extract the year, month and day? Thanks Bob
var date='1/1/2011';
var parseDate = date.split('/');document.write('year - ' + parseDate[2] + '
');
document.write('month - ' + parseDate[1] + '
');
document.write('day - ' + parseDate [0] + '
');as if the facebook, twitter and message boards weren't enough - blogged
-
I have a string in the form of d+/d+/d+. For example, the string might be 1/1/2011. This string would represent the date January 1, 2011. This application uses a banker's year. That means 30 days for each and every month and 360 days to the year. Now, if I have this string in a variable d1 what is the best way to extract the year, month and day? Thanks Bob
You can use the more accurare way,
var date = new Date(d1);
//get your date components like so:
var day = date.getDay();
var month = date.getMonth();
var year = date.getYear();See link here: - http://www.w3schools.com/js/js_obj_date.asp[^] Happy coding, Morgs