Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP/MySQL format date onBlur

Posted on 2011-02-22
4
Medium Priority
?
511 Views
Last Modified: 2012-05-11
I have a form where a user will enter a follow-up date.  However, he doesn't want to have to enter the date in the yyyy/mm/dd format required by MySQL.  Is there a javascript that anyone knows of that will allow him to enter mm/dd/yyyy and, onBlur, have it correct it to yyyy/mm/dd format?  I can't seem to find such a script.  Thanks!
0
Comment
Question by:ssailer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:Proculopsis
ID: 34952759

Try something like this:

<html>

<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26839012.html</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="http://filedb.experts-exchange.com/incoming/2011/02_w07/406422/DateExtension.js" type="text/javascript"></script>
<script>

$(function() {

  $("#format").click( function() {
    var date = new Date( $("#date").val() );
    var sqlDate = date.toString( "YYYY/MM/dd" );
    $("#date").val( sqlDate );
  });

});

</script>
</head>
<body>

<input id="date" value="22 feb 2011" />
<input id="format" type="button" value="Format">

</body>
</html>

Open in new window

0
 

Author Comment

by:ssailer
ID: 34952925
I'm actually looking for something that would do it onBlur, instead of onClick.  I'm just not good with javascript.  
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 1000 total points
ID: 34953041

Just change the line:

  $("#format").click( function() {

to:

  $("#date").blur( function() {
0
 

Author Closing Comment

by:ssailer
ID: 34953134
Worked perfectly.
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question