Thanks to Kaht who gave me this code to convert a calendar date to a julian date.
Can anyone tell me how i can change the input format from mm/dd/yy to dd/mm/yy.
I would also like to show the result in a text box rather than an alert.
Sorry to be a pain but I am still not very good at javascript and am feeling confused.
Code:
<script type="text/javascript">
//set an array with day counts for all months
var dayCount = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
function convertDate(str) {
//convert passed string to date object
var dte = new Date(str);
//initialize date variable
var julianDate = 0;
//add days for previous months
for (i = 0; i < dte.getMonth(); i++) {
julianDate += dayCount[i];
}
//add days of the current month
julianDate += dte.getDate();
//check for leap year
if (dte.getFullYear() % 4 == 0 && dte.getMonth() > 1) {
julianDate++;
}
alert("Julian Date: " + julianDate);
return julianDate;
}
</script>
<body>
<input type="text" id="txt" /><br>
<input type="button" value="get julian date" onclick="convertDate(document.getElementById('txt').value)" />
</body>
Can anyone tell me how i can change the input format from mm/dd/yy to dd/mm/yy.
I would also like to show the result in a text box rather than an alert.
Sorry to be a pain but I am still not very good at javascript and am feeling confused.