Re: Converting Date for mysql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stuart Felenstein wrote:

I have one of those widget calendars.
Mysql keeps throwing back the date regardless of the way I format it. I'm passing session variables over to the database and
have tried quotes ' around the date as well.


Now I went ahead and changed this line:

$_SESSION['f3k'] = $_POST['DateAvailable'];

to

$_SESSION['f3k'] = date('Y-m-d',
mktime(0,0,0,substr(3,5,$_POST['newdate']), substr(0,2,$_POST['newdate']),
substr(6,10,$_POST['newdate'])));


I now tried to pass 'newdate' into the database and
still rejected.

Are you sure it's the date that's causing the rejection? What does mysql_error() say?


Dates (in MySQL) can be formatted in two ways: YYYYMMDDHHMMSS or YYYY-MM-DD HH:MM:SS. The second example is a string while the first is an integer. If you really have just a DATE (instead of DATETIME/TIMESTAMP) column, then it'd be YYYYMMDD and YYYY-MM-DD (although any delimiter should work).

$newdate = '20041231';
$query = "UPDATE table SET datecolumn = $newdate WHERE ... ";

$newdate = '2004-12-31';
$query = "UPDATE table SET datecolumn = '$newdate' WHERE ... ";

--

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux