homepage Welcome to WebmasterWorld Guest from 54.166.105.24
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Month if condition meet
if condition
chrissim




msg:4146249
 1:01 pm on Jun 3, 2010 (gmt 0)

hi,

Any idea how to use the if condition eg: if my timestamp fall on june hours minutes and second? i tried on the date('m') but it didn't work.


//MONTH (june)
$timestamp = time();
$month_start_time = strtotime("june 00:00:00");
$month_end_time = strtotime("june 23:59:59");
$date = time();

if (date('m') == date('m',strtotime('june'))) {

$data = mysql_query("SELECT `items` FROM `log` where `timestamp` >= '".$month_start."' AND `timestamp` <= '".$month_end."'")
or die(mysql_error());
$month=mysql_num_rows($data);

Print "<tr>";
Print "<td class='userbg'><font class='userft'>Order : $month</font></td></tr>";

} else {
Print "No Order";
Print "</table>";
print "\n";
}


 

Alcoholico




msg:4146290
 2:22 pm on Jun 3, 2010 (gmt 0)

The solution, at least not the simplest is not in PHP itself but in MySQL, try this query:

SELECT items
FROM log
WHERE DATE_FORMAT( FROM_UNIXTIME(timestamp), '%m' ) = 6


I presumed "timestamp" is a real UNIX timestamp, if it is not just remove "FROM_UNIXTIME".

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved