Wednesday, May 30, 2012

Code to fix Datepicker Issue

Had an issue where the dates across the site were being displayed in the format: yyyy-mm-dd
Found this code was real useful. 
Ended up fixing everything:
 
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.19.custom.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#startDate").datepicker({ dateFormat: 'dd-mm-yy' });
        $('#ui-datepicker-div').css('display', 'none');
    });
</script>

This code:    $('#ui-datepicker-div').css('display', 'none');
Removes the extra line that appears below the Datepicker.

Later found that in some pages while the display format had changed the data was being picked as mm/dd/yyyy. 
This was happening for days in the month before the 10th. 
Turns out vb automatically changes its date formats until it finds a correct date.
But also for dates before the 10th of every month it assumed that the dates had past.
After much google, thank you Lord for Google
Found this, seemed to fix the problem:

Sub Session_OnStart
  ' Use UK English settings so CDate parses dd/mm/yyyy (rather than US format)
  Session.LCID = 2057
End Sub

Place it in global.asa file so that don't have to keep pasting everywhere
Worked fine!