Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2005-01-15, 03:21 PM
Junior Member
 
Join Date: Jul 2004
Location: MI
Posts: 16
ziriya
Send a message via ICQ to ziriya Send a message via AIM to ziriya Send a message via MSN to ziriya
Default

This is probably something stupid that I'm doing...

Code:
printf("<h2>Birthday: %s</h2>\n", date('m-d-Y', $myrow["birthday"]));
printf("<h2>Birthday: %s</h2>\n", $myrow["birthday"]);
The top statement outputs an incorrect date: Birthday: 12-31-1969

While the bottom statement correctly outputs:
Birthday: 12-17-1977

I'm sure both statements were run on the same record in my database (plus 12-31-1969 isn't anywhere in the database).

Thanks!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2005-01-15, 09:32 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

12-31-1969 is 0 when using a UNIX timestamp.

See: http://www.php.net/date for the correct usage of the date function. This basically means you are not storing the date as a timestamp, which date() needs, you are storing it as a string.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #3 (permalink)  
Old 2005-01-27, 02:07 AM
Junior Member
 
Join Date: Jul 2004
Location: MI
Posts: 16
ziriya
Send a message via ICQ to ziriya Send a message via AIM to ziriya Send a message via MSN to ziriya
Default

The field is set as a date type in MySQL. Is the date changed into a string when it is pulled out by the query?
Reply With Quote
  #4 (permalink)  
Old 2005-01-27, 07:39 AM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

it is a string, but that is not the problem since PHP is not a strongly typed language.

The problem, is that date format (10/10/2004) is not a timestamp (103928853) that the date() function needs.

http://www.php.net/date
http://www.php.net/strtotime
http://www.php.net/mktime
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #5 (permalink)  
Old 2005-01-28, 08:04 PM
Junior Member
 
Join Date: Jul 2004
Location: MI
Posts: 16
ziriya
Send a message via ICQ to ziriya Send a message via AIM to ziriya Send a message via MSN to ziriya
Default

I understand what you are saying now... thanks!
Reply With Quote
  #6 (permalink)  
Old 2005-02-23, 02:02 PM
Junior Member
 
Join Date: Feb 2005
Posts: 1
ellenr
Default

I have a mysql table with a field: cdate of type: timestamp, length 8. I am trying to update the record as follows:
$cp = "Mixed Rule (See Explanation)"; $m=trim($_POST['misc']);
$d=date("Ymd");
$sql = "UPDATE golfcourse SET
cpath='$cp',
cmsg='$m'
cdate='$d'";
if ( !@mysql_query($sql)) {
echo( '

Error updating Course Information: ' .
mysql_error() . '</p>');
}

I get the following error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'cdate='20050223'' :angry:

What am I doing wrong? I thought any timestamp would update itself when the record was "touched" - but it doesn't update if I just update cpath and cmsg.

NM--I see my missing comma in the sql--amazing how many times I looked at this without seeing it! Anyway, why didn't it automatically update the timestamp? Does it have to be the full length timestamp to work that way?
Reply With Quote
  #7 (permalink)  
Old 2005-02-23, 02:15 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

date() does not return a timestamp, it returns a string.

You may be after the http://www.php.net/time() function.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:22 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.