a couple questions about the now() function

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

a couple questions about the now() function

Post by Jr »

1. If I insert that into the database do I need to make the table column a $date format?

2. If I want to return that value from the DB does the column/cell need to be a $date format to return a 'partial' date or do I just use a PHP function to only print a partial date?

and...

3. How do I return a partial or differently formatted date then what is saved to the database?

Thanks for the help...
Jr-
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

1, I think so. Although a timestamp would work too.

2, Yes, you'll need some form of date field to use the date functions.

3, DATE_FORMAT(). It's almost the same as the PHP date() command, but there's a couple of small differences in the format string. Look in the MySQL docs for a reference.
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

I get kind of confused with this MySQL/PHP stuff, is it something like this (except this doesnt work otherwise I wouldn't be asking).

Code: Select all

$m_query = mysql_query( &quote;SELECT * FROM table&quote; );

while ( $m_result = mysql_fetch_array($m_query) )
{
$m_date = ($m_resultїm_date]); //Format Date
print &quote;$m_date&quote;;
}
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Take a look at this post

viewtopic.php?t=32956
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

wha? I'm looking to format the date not figure out how to print results from a database.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Code: Select all

$m_date = date("m/d/Y", strotime($m_result['m_date']));
echo $m_date;
look at date() for all of the different formatting options.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Maby didnt read the post that well enough but you could of fooled me :roll:
Post Reply