Page 1 of 1

how to get datetime object with value 0 or null?

Posted: Fri Mar 16, 2012 12:07 pm
by kc11
Hi,

I would like to get a dateTime object with the value of 0 or null.

I've tried:

Code: Select all


 $nulldate=new DateTime('0000-00-00');
       $nd= $nulldate->format('Y-m-d');  
       
       echo $nd;

This gives me:
-0001-11-30
Any ideas?

Thanks in advance,

KC

Re: how to get datetime object with value 0 or null?

Posted: Fri Mar 16, 2012 12:34 pm
by Celauran
What are you trying to accomplish here?

Re: how to get datetime object with value 0 or null?

Posted: Fri Mar 16, 2012 12:40 pm
by kc11
I want to load this into a mysql db. I am using rebeanphp orm. which does not ( as far as I can tell ) have a way to explicitly set the mysql field type , so by passing it a datetime object, I can set the mysql field to type date.

Thanks,

Re: how to get datetime object with value 0 or null?

Posted: Fri Mar 16, 2012 12:41 pm
by Celauran
Just leave it NULL.

Re: how to get datetime object with value 0 or null?

Posted: Fri Mar 16, 2012 12:49 pm
by kc11

Code: Select all

$nulldate=new DateTime(NULL);
$nd= $nulldate->format('Y-m-d');
echo $nd;
 


returns the current date

Re: how to get datetime object with value 0 or null?

Posted: Fri Mar 16, 2012 12:50 pm
by Celauran
I mean if you don't want a date in the database, let the field be NULL.

Re: how to get datetime object with value 0 or null?

Posted: Fri Mar 16, 2012 1:07 pm
by kc11
I'm not sure how to do that. Is there a sql command for that?

Re: how to get datetime object with value 0 or null?

Posted: Fri Mar 16, 2012 1:13 pm
by Celauran

Code: Select all

ALTER TABLE table_name CHANGE field_name field_name DATETIME NULL

Re: how to get datetime object with value 0 or null?

Posted: Fri Mar 16, 2012 1:17 pm
by kc11
Thank you, I'll check it out and open a new thread if I run into problems.

Best Regards,

KC