| | |
mysql date ALWAYS = 0000-00-00 00:00:00
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hey, I've got a form that passes the date onto a php script, which posts all the form entries into a database. One of those fields happens to be a date field. I have it going into a column in a mysql database that has the DATETIME datatype, but no matter how I work the code, it always goes into the database as 0000-00-00 00:00:00. I know I'm passing the date correctly through the form, because I've echo'd out the variable and it shows the correct date. I'm thinking my problem is on the mysql database, but can't figure it out!
For now, I've just changed the datatype to VARCHAR in that field, and it's working, but I'd very much like to use the DATETIME datatype. Any ideas?
For now, I've just changed the datatype to VARCHAR in that field, and it's working, but I'd very much like to use the DATETIME datatype. Any ideas?
Please post a sample of the data you are attempting to enter.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Try something like:
[php]
function mysql_date($year, $month, $day, $hour, $min, $sec) {
return date("Y-m-d H:i:s", mktime($hour, $min, $sec, $month, $day, $year));
}
[/php]
[php]
function mysql_date($year, $month, $day, $hour, $min, $sec) {
return date("Y-m-d H:i:s", mktime($hour, $min, $sec, $month, $day, $year));
}
[/php]
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
•
•
Try something like:
[php]
function mysql_date($year, $month, $day, $hour, $min, $sec) {
return date("Y-m-d H:i:s", mktime($hour, $min, $sec, $month, $day, $year));
}
[/php]
That worked perfectly. I didn't realize I was passing [PHP]date("Y-m-d")[/PHP] to the database and it was expecting [PHP]date("Y-m-d H:i:s")[/PHP]
Hey, I learn something new on this forum every day. And I also found a chart on the php website that shows all the time tags to put in. Thanks for the info!
![]() |
Similar Threads
- reformatting MySQL date (yyyy-mm-dd) (PHP)
- MySQL SELECT rows In a Date Range (MySQL)
- Inserting date in format DD-MM-YYYY in MySQL (MySQL)
- PHP/Mysql (PHP)
- Date(00/00/0000) formatted textfield (Community Introductions)
Other Threads in the PHP Forum
- Previous Thread: php plan for a voting system?
- Next Thread: Preview Upload Image Problem
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code codingproblem cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select send server sessions sms snippet soap source space speed sql static structure syntax system table tutorial up-to-date update upload url validation validator variable video web wordpress xml youtube






