I am just few days old in javascript and jquery.my question is first select date from date picker or calendar and easily convert this date into week number. Please help me because i don't know anything about that..plzzzzz
Asked
Active
Viewed 1,994 times
1
-
@AnoopJoshi like, 47, 52 week of the year, Nilesh More cant you google it a little bit, i think you will be able to find something out there. – Vitaliy Terziev Nov 20 '15 at 09:53
-
see this http://jsfiddle.net/Fa8Xx/3785/ – Anoop Joshi P Nov 20 '15 at 09:54
-
Welcome to StackOverflow. Check the StackOverflow's help on asking questions first, please. Focus on [How to ask a good question](http://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve), but also other [help topics](http://stackoverflow.com/help/asking) would be useful. – David Ferenczy Rogožan Nov 20 '15 at 10:39
-
@Anup-Week number means 1 to 53 depending on selected date – Nilesh More Nov 20 '15 at 10:57
2 Answers
0
Using Jquerys date picker try the following
HTML
<input type="text" class="calendar">
JS
$(".calendar").datepicker({
showWeek: true,
onSelect: function(dateText, inst) {
alert("Week " + $.datepicker.iso8601Week(new Date(dateText)));
}
});
ahervin
- 461
- 2
- 15
-
hello sir, i used your code for my project but I run individual program it worked excellent. but when I merged it with my KPI tracking Tool project then it doesnt work,it gives "Uncaught typeError: $(...) datepicker is not function." please help me. My code is below, $(".calendar").datepicker({ altField : "#alternate1", altFormat : "DD, d MM, yy", onSelect: function(dateText) { var date = $(this).datepicker('getDate'); $("#alternate").val(+date.getFullYear()); $(this).val("week number"+ $.datepicker.iso8601Week(new Date(dateText))); } }); – Nilesh More Nov 26 '15 at 14:09
-
@NileshMore See this answer http://stackoverflow.com/questions/1212696/jquery-ui-datepicker-datepicker-is-not-a-function – ahervin Nov 26 '15 at 16:14
0
Try this code to get the week from the given date. http://jsfiddle.net/3TA4s/134/
<input type="text" placeholder="date1" id="startdate">
<input type="text" placeholder="date2" id="enddate">
<input type="text" id="days">
<script>
$(document).ready(function() {
$( "#startdate,#enddate" ).datepicker({
changeMonth: true,
changeYear: true,
firstDay: 1,
dateFormat: 'dd/mm/yy',
})
$( "#startdate" ).datepicker({ dateFormat: 'dd-mm-yy' });
$( "#enddate" ).datepicker({ dateFormat: 'dd-mm-yy' });
$('#enddate').change(function() {
var start = $('#startdate').datepicker('getDate');
var end = $('#enddate').datepicker('getDate');
if (start<end) {
var days = (end - start)/1000/60/60/24/7;
$('#days').val(parseInt(days));
}
else {
alert ("You cant come back before you have been!");
$('#startdate').val("");
$('#enddate').val("");
$('#days').val("");
}
}); //end change function
}); //end ready
</script>
Sathish
- 337
- 1
- 9
-
-
I didnt notice that. Just sont want to use for the two times. Thanks @Cobote – Sathish Dec 12 '15 at 05:35