Page 1 of 1
Date returned as 00/00/0000 rather than blank
Posted: Thu May 16, 2002 2:56 pm
by sknelson
I run a macro in a Microsoft Access database to convert the data to MySQL. If a date field is empty in Access, it remains empty in the "Insert Record" code that is created by the macro, but when I insert the text file into MySQL, the date is changed to 00/00/0000. When I query the data and post it to a PHP results page on my website, I would like the date field to be blank rather than return 00/00/0000. Could anyone help me out with this? I can find all kinds of help for formatting date fields, etc. but nothing about this problem.
Thanks much for any assistance!
Posted: Sun May 19, 2002 12:42 pm
by sam
Because you are using a mysaql date field rather than an int or timestamp field there is no way to rid yourself of the 00/00/0000 format. I would suggest you looking using timestams to store your dates.
Cheers Sam
Different script solved the problem
Posted: Mon May 20, 2002 9:57 am
by sknelson
I downloaded ExportSQL script from
http://www.cynergi.net/exportsql/ and it worked great! It puts "Null" in as the value rather than leaving it blank and that took care of my problem. Thanks for the help.
Posted: Tue May 21, 2002 2:42 pm
by sam
no problem.
Cheers Sam
Posted: Thu May 23, 2002 10:53 am
by Crashin
When I want to display dates, but not the 0000-00-00 default that MySQL uses for NULL values, I use the following code to check the date and display nothing if appropriate:
Code: Select all
if ($date_variable != "0000-00-00") {
list($year, $month, $day) = split('ї-./]', $date_variable);
$date_variable = date('m/d/Y',mktime(0,0,0,$month,$day,$year));
}
else {
$date_variable = "";
}
Enjoy, in case you still need it!