473,320 Members | 1,993 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

view date as dd-mm-yyyy but insert to mysql as yyyy-mm-dd

I have been trying my best to display a chosen date as dd-mm-yyyy but insert it into the mysql database as yyyy-mm-dd, I know it must be simple but no matter what I try I can't get it to work.

Code:

<?php require_once('../Connections/wind.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO readings (windyboy, white, `date`, meter) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['windyboy'], "int"),
GetSQLValueString($_POST['white'], "int"),
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['meter'], "int"));

mysql_select_db($database_wind, $wind);
$Result1 = mysql_query($insertSQL, $wind) or die(mysql_error());
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<SCRIPT LANGUAGE="JavaScript" SRC="/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var cal = new CalendarPopup();
</SCRIPT>
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<p>windyboy
<input name="windyboy" type="text" id="windyboy" />
</p>
<p>white
<input name="white" type="text" id="white" />
</p>
<p>date
<input name="date" type="date" id="date" />
<A HREF="#"
onClick="cal.select(document.form1.date,'anchor1', 'yyyy-MM-dd'); return false;"
NAME="anchor1" ID="anchor1">select</A>
</p>
<p>meter
<input name="meter" type="text" id="meter" />
</p>
<input type="hidden" name="MM_insert" value="form1">
submit
<input type="submit" name="Submit" value="Submit" />
<input type="hidden" name="hiddenField" />
</form>
</body>
</html>
Jan 5 '08 #1
2 2870
Markus
6,050 Expert 4TB
Please use CODE tags.

Couldn't make out what you wanted unfortunately..
[php]
<?php
$__date = date("D:m:y");
$__date = explode(":", $__date);
$__date = $__date[2].$__date[1].$__date[0];
echo $__date;
?>
[/php]

If you're using javascript you should head over to that forum.
Jan 6 '08 #2
As suggested went to javascript forum and the issue has been sorted

Thanks

Gordon
Jan 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: puppet_sock | last post by:
Here's what I want to do. I want a view that restricts to rows that are "in date" when a working date exists, but shows the whole table when no date exists. I have a temporary global...
1
by: Mark | last post by:
Hi, I'm trying to write a view that returns a historical view of records as of a certain date. The records come from a live and historical table and I need to return the records as they were in...
2
by: Rubia 078 | last post by:
I have a table tblElectronic that recieves data electronically. It contains fields: filenumber, status, date, qualifier and comments. The qualifier field is either 100 or 101, meaning the file is...
6
by: _link98 | last post by:
Problem: getting SQL0181N for queries on nicknames to remote Union-All-View. Can't see what I'm doing wrong yet, maybe someone has seen this before. Environment: UDB ESE 8.1 + FIXPAK 9A, on...
2
by: David C | last post by:
I am looking for some kind of calendar view control that I can show hyperlinks to records in day cells. This is to be used for showing scheduled events and people can see events in a calendar view...
12
by: Raed Sawalha | last post by:
I have the following table which i can not switcha to design view error message said Could not open in Design view. Quote values differently inside a '<% ...."value"... %>' block. and the...
20
by: raptor | last post by:
hi, I want to make the following thing : select-based updatable VIEW, which have two more virtual-fields. One of them is concatenation of others and the second is calculated on the fly. Can I...
4
by: JayCallas | last post by:
I have a SQL 2000 table containing 2 million rows of Trade data. Here are some of the columns: INT IDENTITY(1,1) -- PK, non-clustered DATETIME -- clustered index ...
9
by: harborboy76 | last post by:
Hi, I have a problem with one of my view. Basically, I need to create a view to sum the amount in Table A grouped by the EMPLOYEE_ID. But I also need the ability to limit the date range. What...
2
by: cjshea | last post by:
Hello Friends; I am asking this as a database administrator, perhaps more on behalf of the SQL Programmer. We have a search on a view that uses a street number and a partial street name in a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.