inserting dates/times in DB

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

Post Reply
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

inserting dates/times in DB

Post 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-
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Code: Select all

INSERT INTO MYTABLE (dttm) values (now())
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

um... ok?? so what exactly is changed from a normal insert? And what is a now() function?
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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. ;)
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post 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?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Please post your code.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

cool, thanks
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post 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-
Post Reply