PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
kc11
Forum Commoner
Posts: 73 Joined: Mon Sep 27, 2010 3:26 pm
Post
by kc11 » Fri Mar 16, 2012 12:07 pm
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
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Mar 16, 2012 12:34 pm
What are you trying to accomplish here?
kc11
Forum Commoner
Posts: 73 Joined: Mon Sep 27, 2010 3:26 pm
Post
by kc11 » Fri Mar 16, 2012 12:40 pm
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,
Last edited by
kc11 on Fri Mar 16, 2012 12:43 pm, edited 1 time in total.
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Mar 16, 2012 12:41 pm
Just leave it NULL.
kc11
Forum Commoner
Posts: 73 Joined: Mon Sep 27, 2010 3:26 pm
Post
by kc11 » Fri Mar 16, 2012 12:49 pm
Code: Select all
$nulldate=new DateTime(NULL);
$nd= $nulldate->format('Y-m-d');
echo $nd;
returns the current date
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Mar 16, 2012 12:50 pm
I mean if you don't want a date in the database, let the field be NULL.
kc11
Forum Commoner
Posts: 73 Joined: Mon Sep 27, 2010 3:26 pm
Post
by kc11 » Fri Mar 16, 2012 1:07 pm
I'm not sure how to do that. Is there a sql command for that?
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Mar 16, 2012 1:13 pm
Code: Select all
ALTER TABLE table_name CHANGE field_name field_name DATETIME NULL
kc11
Forum Commoner
Posts: 73 Joined: Mon Sep 27, 2010 3:26 pm
Post
by kc11 » Fri Mar 16, 2012 1:17 pm
Thank you, I'll check it out and open a new thread if I run into problems.
Best Regards,
KC