close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

How to format DatePicker date to dd/mm/yyyy so that it displays correctly in the form field and is validated correctly?

Thread began 12/09/2013 11:56 am by FPhu61701534 | Last modified 12/10/2013 11:50 am by Jason Byrnes | 4502 views | 6 replies |

FPhu61701534

How to format DatePicker date to dd/mm/yyyy so that it displays correctly in the form field and is validated correctly?

I understand that MySQL stores date in Y-m-d H:i:s format. However, I want to generate dates based on dd/mm/yyyy and display in this format in the form field once the date is picked (and validated as dd/mm/yyyy). Unfortunately, it doesn't work. I tried all the methods described in the other threads but still can't get it work. I experimented with different permutations and ended up getting invalid format warning, incorrect format or 1/1/1970.

Can you advise what I should do? I have run out of idea how to make this work. Here are the codes in questioned:

DatePicker...
$(function(){
$('#session_date_start').datepicker({
changeMonth: true,
changeYear: true,
dateformat: "dd/mm/yy",
onClose: closeDatePicker_session_date_start
});

Form Field...
<input id="session_date_start" name="session_date_start" type="text" value="<?php echo((isset($_GET["invalid"])?ValidatedField("sessionupdate","session_date_start"):"".(($row_WADAsession["session_date_start"])?date("d/m/Y",strtotime($row_WADAsession["session_date_start"])):"")."")); ?>" class="formTextfield_Medium" tabindex="4" onBlur="hideServerError('session_date_start_ServerError');">
});

Spry Validation...
var session_date_start_Spry = new Spry.Widget.ValidationTextField("session_date_start_Spry", "date",{ format:'dd/mm/yyyy' , validateOn:["blur"]});

Attached is the php file. The problematic field is: session_date_start. Once this issue is solved, I will replicate the correct formatting to the other date fields.

Sign in to reply to this post

FPhu61701534

I have included the site address in the private message.

Sign in to reply to this post

Jason ByrnesWebAssist

in the datepicker code, you have:
dateformat: "dd/mm/yy",

this is not valid, the f needs to be capitolized:
dateFormat: "dd/mm/yy",

Sign in to reply to this post

FPhu61701534

It doesn't fix the issue even after I capitalized dateFormat. I just tried updating record ID 3 (Email Marketing) using dateFormat but ended up getting 1 Jan 1970. Actually, I have been using dateFormat with capital F over the last two days without success.

Sign in to reply to this post

Jason ByrnesWebAssist

so the issue now not that it is not passing validation, but what is being stored in the database, right?

in the update behavior, the code has to reformat the date to be compatible with MySQL. it uses the date and strtotime function refomat the date to yyyy-mm-dd H:i:s format:

date("Y-m-d H:i:s", strtotime($_POST["session_date_start"]))


the problem with this is that the strtotime function uses the separator to determine if the data uses the US Format or the UK format. From the php web site:
http://php.net/manual/en/function.strtotime.php

  Note:
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.  



When the separator uses a slash, strtotime assumes the US m/d/y format, but you are passing it as d/m/y

one of 2 way to fix it:
1) Use the dash separator instead

2) add code at line one of your page to convert the slash to a dash
<?php if(isset($_POST["session_date_start"])) $_POST["session_date_start"] = str_replace("/","-",$_POST["session_date_start"]); ?>

Sign in to reply to this post

FPhu61701534

It works now. Thanks for the help!

One more thing, is it possible to display the date in my form as say 11 Dec 2014 rather than 11/12/2014? Meaning, when the form loads, it pre-populates the text field with the date from the recordset in 11 Dec 2014. Then when I pick a date from the picker, it can also display in the same format. When the form submits, it will send the date according to MySQL's format.

Sign in to reply to this post

Jason ByrnesWebAssist

No, the date picker does not support that date format.

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...