dates with different formats change to 1 dateformat

Hi There

I have a question about dateformats

I am searching for a solution/validation for the next problem. in the formfields I get 2 different dates:
yyyy-mm-dd and dd-mm-yyyy. Is there a javascript to think of. doing the following:

if (date = dd-mm-yyyy) {convert to yyyy-mm-dd}

I hope someone can help me

regards

ron
Ron BaasDirecteurAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
OK. You've tagged this as PHP and Javascript, so not sure what you need. You mention formfields. Are you wanting to handle the form data once it's passed back to your server (i.e. PHP).

If you are talking about client-side, is there are a reason why you have different date formats in your HTML. It would make sense to normalise those
1
Ron BaasDirecteurAuthor Commented:
Hi Chris

It is a very strange problem, this is the formfield:

  <div class="form-group">

       Opdrachtdatum
         <input type="date" placeholder="jjjj-mm-dd" name="opdrachtdatum" class="form-control"/>
     </div>


some dates are   yyyy-mm-dd    and some dates are   dd-mm-yyyy.

I hav also attached de file. I hope you can help me with this strange problem

thanks

ron
0
Chris StanyonWebDevCommented:
Hey Ron,

You haven't attached any files.

Basically, if your inputs are set to the date type, then the values that are submitted should all be normalised to the standard date format - yyyy-mm-dd - when your form is sent to the server. The inputs may display a different format to the user as this is based on locale, but the actual value submitted should always be in the standard format.

Now if your inputs are just plain text inputs, then the browser will do nothing to sort your dates out and the data sent will be in whatever format the user typed it in.

Would probably need to see your code to help you out further.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Ron BaasDirecteurAuthor Commented:
Hi Chris

Thanks, I'll try it this way
0
Ron BaasDirecteurAuthor Commented:
Hi Chris or someone else,

I have still one problem with my form.
For the database is the date perfect but for the emailsending I prefer  mm-dd-yyyy.

I hope you can help me with this  the inputfield is:  "opdrachtdatum"  
I have make a hiddenfield with  the name  "neddatum"  and a javascript function dataform.
The "neddatum" value should be dd-mm-yyyy

Regards Ron
bestellingtest.php
0
Chris StanyonWebDevCommented:
Hey Ron,

Something I'm unsure of in your code. You have your 2 date fields - afvoer and opdrachtdatum, and these will be sent to the server when you submit the form, so I don't really understand why you have a hidden field. All you seem to do with that hidden field is set it to the value of opdrachtdatum when you submit the form. This would effectively give you the same value in 2 different form fields - $_POST['opdrachtdatum'] and $_POST['neddatum'].

As for the date format, a DatePicker will always submit the value in the yyyy-mm-dd format, regardless of how it's displayed on the screen. As you say, this is perfect for the Database. If you want to change the format of it for your email, you simply create a new DateTime object from the value and then call the format() method when you use it, passing in the format string you want to output. So in your PHP scripts, you would do something like the following:

// create a date time Object
$toDate = new DateTime( $_POST['opdrachtdatum'] ); // 2016-06-15

// format it 
echo $toDate->format( 'm-d-Y' );  // 15-06-2018
echo $toDate->format( 'jS F Y' ); // 15th June 2018

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ron BaasDirecteurAuthor Commented:
thanks chris
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.