Jump to content

Help! mysql date format from form


jaquelyn

Recommended Posts

Hi!  I'm trying to process a date field on a form where the input is m/d/Y and I can't figure out how to have that entered as the appropriate Y-m-d mysql format.  I've tried a thousand things, but I'm doing something wrong.  And I can't use a dropdown.  Users must be able to enter the date in m/d/Y format.  Thank you for any help you can offer!  Here is the code:

 

$currentPage = $_SERVER["PHP_SELF"];

 

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {

  $insertSQL = sprintf("INSERT INTO tbl_timerecords (fd_date, fd_client, fd_task, fd_hours, fd_description, fd_status, fd_notes, fd_user) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",

                      GetSQLValueString($_POST['fd_date'],"date"),

                      GetSQLValueString($_POST['fd_client'], "text"),

                      GetSQLValueString($_POST['fd_task'], "text"),

                      GetSQLValueString($_POST['fd_hours'], "double"),

                      GetSQLValueString($_POST['fd_description'], "text"),

                      GetSQLValueString($_POST['fd_status'], "text"),

                      GetSQLValueString($_POST['fd_notes'], "text"),

                      GetSQLValueString($_POST['fd_user'], "text"));

 

Link to comment
Share on other sites

I actually tried that - Doesn't work at all, BUT just found the solution to my problem here:

 

http://dreamweaverforum.info/dreamweaver-general/126952-send-text-entered-mm-dd-yyyy-mysql.html

 

The code snippet to be added is:

 

function UStoMySQL($date) {

// split the date on forward slashes

$parts = explode('/', $date);

// if split successfully, rearrange in the MySQL order

if (is_array($parts) && count($parts) == 3) {

return "$parts[2]-$parts[0]-$parts[1]";

} else {

return false;

}

}

$_POST['fd_date'] = UStoMySQL($_POST['fd_date']);

 

This should be added just above the "if ((isset($_POST..." line.

 

Thanks!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.