Page 1 of 1
inserting dates/times in DB
Posted: Thu Apr 28, 2005 11:11 am
by Jr
ok, so I have a pretty good database set up but I was just informed that I am inserting dates into it incorrectly. I am currently just inputing them in as a string but I was told to input them as an actual $date datatype. Anyone know how I go about doing this?
Thanks,
Jr-
Posted: Thu Apr 28, 2005 11:14 am
by hawleyjr
Code: Select all
INSERT INTO MYTABLE (dttm) values (now())
Posted: Thu Apr 28, 2005 11:23 am
by Jr
um... ok?? so what exactly is changed from a normal insert? And what is a now() function?
Posted: Thu Apr 28, 2005 11:42 am
by Skara
I'd think it was pretty obvious. >.> Guess not.
now() = now. as in currently. as in the current time/date/both.
Nothing is changed from a normal insert. it IS a normal insert. the now() function is the only thing you should be concerned about.

Posted: Thu Apr 28, 2005 12:08 pm
by Jr
I'm sorry... I asked that incorrectly. I looked now() in the manual and nothing came up. I tried it and got a PHP error saying "undefined function." Can someone tell me how it works or a valid function for what I'm looking for?
Posted: Thu Apr 28, 2005 12:10 pm
by hawleyjr
Please post your code.
Posted: Thu Apr 28, 2005 12:22 pm
by John Cartwright
now() is a mysql function, not php. You may run now() in a query to get the current time.
A good place to begin is
http://dev.mysql.com/doc/mysql/en/date- ... rview.html
Ohh the glorious mysql manual.
Posted: Thu Apr 28, 2005 12:41 pm
by Jr
cool, thanks
Posted: Thu Apr 28, 2005 5:30 pm
by Jr
ok a couple more questions about that now() function.
1. do you need to insert that into the DB do I need to make the table column/cell $date formatted?
2. If i want to return that from the DB does the column/cell need to be a $date format to return a 'partial' date?
and...
3. How do i return a partial or differently formatted date then what it returns as default just printing from an array?
Thanks for the help...
Jr-