1

I have found that when inserting a record which contains a Date using JSOM the update(); will not work if you specify the format of the date to be UK date (28/05/2014).

The code does not error, it simply won't insert the data. If I change the format of the date to US (05/28/2014) it works but I want to use the UK method, especially when I'm using a data picker etc.

I have tried setting the regional settings to English (UK) within the site settings but this makes no difference.

To add some more detail...my HTML code is

<div class="form-horizontal">
                                <div class="form-group">
                                    <label for="GEDate" class="col-sm-2 control-label">Date:</label>
                                    <div class="col-sm-6">
                                        <input type="text" id="GEDate" name="GEDate" class="form-control" placeholder="Date"  />
                                    </div>
                                </div>
                            </div>

and i use the following in my app.js

$('#GEDate').datepicker({
    format: "mm/dd/yyyy",
    autoclose: true,
    todayHighlight: true
});

where i really want to use

$('#GEDate').datepicker({
    format: "dd/mm/yyyy",
    autoclose: true,
    todayHighlight: true
});

Any kind of manipulation on the value and SharePoint/JavaScript is saving that its invalid.

2

I'm not sure this is possible, have you tried setting the value to a JS date object instead of string? The alternative ofcourse is to write a function which fixes date string by swapping the day and month...

var arr = date.split('/');
var newDate = arr[1] + "/" + arr[0] + "/" + arr[2];
  • I had thought of this as I am using a bootstrap date picker which means the input object is text rather than date. Because of this the JS does not see it as a date object. So yes i guess i could try the above... I'm also considering changing the date field to a text field!! – Stephen May 29 '14 at 18:11
  • To get the date object you can try this: $('#GEDate').val() or $('#GEDate').data('date') – onzur May 30 '14 at 15:05
0

I don't know if this would help or be overkill, Have you considered using the momentjs library?

0

Today i have faced the same issue and i have resolve this, I have done the following things

  1. Changed the regional Settings to India Zone (UTC+5:30) and Locale to United Kingdom (refer screen shot).

  2. While saving using JSOM i have used dateFormat:"mm/dd/yy"

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.