Jump to content

Incorrect datetime value:??


icehawk012

Recommended Posts

Alright, for some reason this script I wrote is working with mySQL 5 but not 4. I've been running through it trying to figure out what's going on but I keep getting the same error :

[quote]News could not be added because: Incorrect datetime value: '9.7.2006 1:41am' for column 'date' at row 1[/quote]

So here's what I've got as far as adding the "News":

[code] } else if (isset ($_POST['submit'])) {
include("db2.php");
$realdate = date ( 'n.j.Y g:ia' );
$writenews = "INSERT INTO park_news (title, content, date) VALUES ('{$_POST['posttitle']}', '{$_POST['postcontent']}', '{$realdate}')";
if (@mysql_query($writenews)) {
print ("<p>News successfully added.</p>");
} else {
print ("<p>News could not be added because: <b>" . mysql_error() . "</b></p>");
}
print ("<img src=\"spacer.gif\" width=\"75%\" height=\"1\" />");
[/code]

Should I be using the time() function to get my date and then reformatting it when it spits it back out?
Link to comment
Share on other sites

Ok, I've got it all figured out so I figured I would update everyone on how it's done. I'm using the MySQL NOW() function, but combining it with the MySQL CONVERT_TZ() function which takes three variables: DATETIME, Timezone1, and Timezone2. Timezone1 being the starting timezone and Timezone2 being the timezone to be converted to. The code ends up looking like so:

[code] } else if (isset ($_POST['submit'])) {
include("db2.php");
$writenews = "INSERT INTO park_news (title, content, date) VALUES ('{$_POST['posttitle']}', '{$_POST['postcontent']}', CONVERT_TZ(NOW(),'+00:00','-07:00'))";
if (@mysql_query($writenews)) {
print ("<p>News successfully added.</p>");
} else {
print ("<p>News could not be added because: <b>" . mysql_error() . "</b></p>");
}
print ("<img src=\"spacer.gif\" width=\"75%\" height=\"1\" />");
[/code]

Works flawlessly.  ;D
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.