1. jimmywiddle
  2. Bug Report
  3. Thursday, July 21 2016, 07:31 AM
Hi, Im attempting to change the format for the date to the following format, but unfortunately im not having much luck, your assistance would be much appreciated!

26-Jul-2016

It should be this format but its not working:

Y-m-d
admin Accepted Answer
Admin
Hi,
try with

j-M-Y


for syntax refer to http://php.net/manual/en/function.date.php
  1. more than a month ago
  2. Bug Report
  3. # 1
jimmywiddle Accepted Answer
Hi, Thanks for your response, but im afraid its not working?
The format is still 2016-07-21

Thanks in advance!
  1. more than a month ago
  2. Bug Report
  3. # 2
admin Accepted Answer
Admin
Hi,
in edit profile you can't change format, this is format required to parse correctly date. The date format is customizable only on profile/user list pages
  1. more than a month ago
  2. Bug Report
  3. # 3
jimmywiddle Accepted Answer
Hi,
Yes im referring to user registration/edit profile.

Im afraid I know my client wont accept this date not being in the same format as the rest of the website (26-Jul-2016).

Could you please possibly point me in the right direction, or advice how I can achieve this, many thanks in advance!
  1. more than a month ago
  2. Bug Report
  3. # 4
admin Accepted Answer
Admin
Hi,
sorry this is not possible with a simple way, you can change format with language override the constant is COM_JSN_DATE_INPUT_FORMAT (now value is yyyy-mm-dd)
BUT:
1. You can't user format like PHP because this is used for javascript, you can change only the order of yyyy, mm, dd
2. You need to test it, because change the order can not works, for example
date like 7 june 2016 will be
yyyy-mm-dd -> 2016-06-07 -> Joomla store correct value
yyyy-dd-mm -> 2016-07-06 -> Joomla store wrong value (6 July 2016)

so you need add some code to convert date into SQL like format.
  1. more than a month ago
  2. Bug Report
  3. # 5
jimmywiddle Accepted Answer
Hi, Thanks again for your reply/help!

I made modified the date format to the following:

31-01-2016

And am currently trying to achieve the months (-Jan- instead of -01-) with some jquery, if you know of any issues with this or a possible better method, please do let me know.
  1. more than a month ago
  2. Bug Report
  3. # 6
jimmywiddle Accepted Answer
Content Protected
  1. more than a month ago
  2. Bug Report
  3. # 7
admin Accepted Answer
Admin
Hi,
you have a javascript error, try to replace this:

var element = $('input[name=jform[preferred_moving_date]]');

with this

var element = $('input[name="jform[preferred_moving_date]"]');
  1. more than a month ago
  2. Bug Report
  3. # 8
jimmywiddle Accepted Answer
Content Protected
  1. more than a month ago
  2. Bug Report
  3. # 9
admin Accepted Answer
Admin
remove all your previous code and try with this:

jQuery(document).ready(function(){
var months = ['Jan','Feb','May','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var element = jQuery('#jform_preferred_moving_date');

element.on('change', function(e) {

var date_parts = jQuery(this).val().split('-');
var month_index = Number(date_parts[1]) - 1;
var date_new = date_parts[0] + '-' + months[month_index] + '-' + date_parts[2];
jQuery(this).val(date_new);
});
});
  1. more than a month ago
  2. Bug Report
  3. # 10
jimmywiddle Accepted Answer
Content Protected
  1. more than a month ago
  2. Bug Report
  3. # 11
jimmywiddle Accepted Answer
...although unfortunetly Ive just spotted that on the 'Edit Profile' page, when the page loads, the date is in the old format, its not until a new date is selected with the calendar, that the date value changes to the correct format.

Im going to come back to it in the morning now, but if a fix jumps at you and you have the time to pop it in a post, id really appreciate it, once again many thanks!!!
  1. more than a month ago
  2. Bug Report
  3. # 12
admin Accepted Answer
Admin
Hi,
now you change format when the value is changed, you can add something that change this also when site is ready, so try use function like this:

jQuery(document).ready(function(){
var months = ['Jan','Feb','May','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var element = jQuery('#jform_preferred_moving_date');

/* ADD THIS */
var date_parts = element.val().split('-');
var month_index = Number(date_parts[1]) - 1;
var date_new = date_parts[0] + '-' + months[month_index] + '-' + date_parts[2];
element.val(date_new);
/* --- --- */

element.on('change', function(e) {

var date_parts = jQuery(this).val().split('-');
var month_index = Number(date_parts[1]) - 1;
var date_new = date_parts[0] + '-' + months[month_index] + '-' + date_parts[2];
jQuery(this).val(date_new);
});
});
  1. more than a month ago
  2. Bug Report
  3. # 13
jimmywiddle Accepted Answer
Content Protected
  1. more than a month ago
  2. Bug Report
  3. # 14
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.