Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   Operating with php date (http://www.greenguysboard.com/board/showthread.php?t=36505)

Xallow 2006-12-01 11:49 AM

Operating with php date
 
Hi guys and gals

I am trying to do the following:

extract a date from my database, it is MySql and stored as a Date, ie. 2006-11-29

compare this date to todays date using date("Ymd") and find out if the date from the datbase is more or less than 7 days ago, I just cant get it to work!

I won't copy my code here, since it is so messed up that nobody would understand it anyway! a working example would be Highly appreciated and almost worth giving a blowjob for.... almost :D

cd34 2006-12-01 12:12 PM

select if('2006-11-01'>date_sub(curdate(),interval 7 day),'within the last week','more than a week old');

something like that will work.

substitute your field name in the place where I put the date

oast 2006-12-01 01:20 PM

I use this basic code to do something similar to what you are looking for.

PHP Code:

<?php
$OneWeekAgo 
date('Y-m-d'mktime(000date("m"), date("d")-7date("Y")));
$query DatabaseQuery("SELECT * FROM table");
while(
$rows mysql_fetch_array($query)){
    if (
$rows[lastaction] < $OneWeekAgo)
        echo 
$rows[name].' last action was more than one week ago ('.$rows[lastaction].')'."\n";
    else
        echo 
$rows[name].' was active <b>within the last week</b> ('.$rows[lastaction].')'."\n";
}
?>

Change the table and field names to suit your needs.

** DatabaseQuery(); is a self made database access function, so you will have to alter the query to suit your needs, but the rest is straightforward.

Xallow 2006-12-02 08:58 AM

thanks guys, it works now


All times are GMT -4. The time now is 11:01 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc