close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Datepicker date format change isn't working

Thread began 1/02/2020 1:04 pm by Mags | Last modified 1/07/2020 10:43 am by Ray Borduin | 805 views | 8 replies |

Mags

Datepicker date format change isn't working

I have the following code for a date range datepicker:

<script>
$( function() {
var dateFormat = "dd/mm/yy",
from = $( "#DatePaid" )
.datepicker({
defaultDate: "-1w",
changeMonth: true,
changeYear: true,
numberOfMonths: 1
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#DatePaidTo" ).datepicker({
defaultDate: "",
changeMonth: true,
changeYear: true,
numberOfMonths: 1
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});

function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}

return date;
}
} );
</script>

<input id="DatePaid" name="DatePaid" type="text" value="" class="formTextfield_Medium" autocomplete="off" />
<input id="DatePaidTo" name="DatePaidTo" type="text" value="" class="formTextfield_Medium" autocomplete="off" />

However the date is still displaying in the format mm/dd/yy instead of dd/mm/yy. Can you see what I've done wrong?

Sign in to reply to this post

Ray BorduinWebAssist

You set a variable with the format, but you never pass it to the datepicker. You would have to add it to the datepicker definitions like:

.datepicker({
dateFormat: dateFormat,
defaultDate: ...
Sign in to reply to this post
Did this help? Tips are appreciated...

Mags

Thanks Ray. I've changed it as follows and now the dates display correctly, however when I search it comes up with zero results even though there are definitely matching records:

<script>
$( function() {
var dateFormat = "dd/mm/yy",
from = $( "#DatePaid" )
.datepicker({
dateFormat: "dd/mm/yy",
defaultDate: "-1w",
changeMonth: true,
changeYear: true,
numberOfMonths: 1
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#DatePaidTo" ).datepicker({
dateFormat: "dd/mm/yy",
defaultDate: "",
changeMonth: true,
changeYear: true,
numberOfMonths: 1
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});

function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}

return date;
}
} );
</script>

Sign in to reply to this post

Ray BorduinWebAssist

That has to do with the server side code that filters the result. I couldn't debug that with the datepicker code alone. If you attach the page I might be able to spot it.

Sign in to reply to this post
Did this help? Tips are appreciated...

Mags

Copy of page attached, thanks!

Sign in to reply to this post

Ray BorduinWebAssist

You are using an "=" comparison for the start date filter. It should be ">=" like:

$searchWADAProc_Fee_DB_WADbSearch1->setSearch(array("type"=>"Edit", "comparison"=>">=", "join"=>"AND"), array("DatePaid"), "t", "DatePaid");

Sign in to reply to this post
Did this help? Tips are appreciated...

Mags

I got the search comparison bit sorted, but it will only work when I set the date format to mm/dd/yy - when I change it to dd/mm/yy it gives me zero results. I've attached an updated copy of the page if you wouldn't mind having a look!

Sign in to reply to this post

Ray BorduinWebAssist

PHP understands slashes with dates as US format and dashes uses UK format. So it should either be: mm/dd/yy or dd-mm-yy

Sign in to reply to this post
Did this help? Tips are appreciated...

Mags

I've changed the format to dd-mm-yy and it all works fine, many thanks!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...