Page 1 of 1

a couple questions about the now() function

Posted: Fri Apr 29, 2005 2:27 pm
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-

Posted: Fri Apr 29, 2005 4:26 pm
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.

Posted: Fri Apr 29, 2005 5:11 pm
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;;
}

Posted: Fri Apr 29, 2005 5:28 pm
by ol4pr0
Take a look at this post

viewtopic.php?t=32956

Posted: Fri Apr 29, 2005 6:33 pm
by Jr
wha? I'm looking to format the date not figure out how to print results from a database.

Posted: Fri Apr 29, 2005 6:42 pm
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.

Posted: Sat Apr 30, 2005 12:13 am
by ol4pr0
Maby didnt read the post that well enough but you could of fooled me :roll: